How to display extended fields in Django Photologue

343 views Asked by At

I've followed the documentation on how to customize models. I want to add an extra url field to the gallery, so I've added this.

extra_url = models.URLField(max_length=200, blank=True, null=True)

Everything shows up fine in the Django admin, but I have no idea how to call up that field in the actual HTML.

The documentation says:

The above code is enough to start entering tags in the admin interface. To use/display them in the front end, you will also need to override Photologue’s own templates - as the templates are likely to be heavily customised for your specific project, an example is not included here.

I have already overridden the Photologue's templates with my own. I'm too much of a novice to figure it out without an example. I've just been guessing with no luck.

  <div class="row col-lg-12">
    <div class="col-xs-6 col-md-8">
        <h1 class="page-header">{{ gallery.title }} </h1>
        <a href="{% however you call up the extra_url field %}">
        <p class="muted"><small> {{gallery.date_added }}</small></p>        

            {% for photo in gallery.public %}
                <div class="col-xs-6 col-xs-3">
                  <a href="{{ photo.get_absolute_url }}">
                       <img src="{{ photo.get_thumbnail_url }}" class="thumbnail" alt="{{ photo.title }}">
                  </a>
                </div>
            {% endfor %}
    <div><a href="{% url 'photologue:gallery-list' %}" class="btn btn-default">{% trans "View all galleries" %}</a></div>
    </div> 
  </div>
1

There are 1 answers

1
Richard Barran On BEST ANSWER

Are you creating an extra model exactly as per the documentation, i.e.:

class GalleryExtended(models.Model):

    # Link back to Photologue's Gallery model.
    gallery = models.OneToOneField(Gallery, related_name='extended')

    # Now your extra field.
    extra_url = models.URLField(max_length=200, blank=True, null=True)

If yes - then within your template you can write {{ gallery.extended.extra_url }} to display that new field.

The key is the related_name, which tells Django how to access the new new model from the existing Gallery - and you already have the Photologue Gallery in your template, as variable {{ gallery }}.