# You have a FK from Image to Album and hence there will only be only 1
Album for every image as per your design
# Have a look at django-photologue for some code-inspiration.

-Venkat



On Mon, May 12, 2014 at 10:47 AM, bradford li <bradfor...@gmail.com> wrote:

> I am trying to display the album titles related to my image in my admin
> interface
>
> class Album(models.Model):
> title = models.CharField(max_length = 60)
>
> def __unicode__(self):
> return self.title
>
> class Tag(models.Model):
> tag = models.CharField(max_length = 50)
>
> def __unicode__(self):
> return self.tag
>
> class Image(models.Model):
> title = models.CharField(max_length = 60, blank = True, null = True)
> image = models.FileField(upload_to = get_upload_file_name)
> tags = models.ManyToManyField(Tag, blank = True)
> albums = models.ForeignKey('Album')
> width = models.IntegerField(blank = True, null = True)
> height = models.IntegerField(blank = True, null = True)
> created = models.DateTimeField(auto_now_add=True)
>
> How I am getting these album titles is with this method
>
> def albums_(self):
> lst = [x[1] for x in self.albums.values_list('albums')]
> return ", ".join(lst)
>
> However it is not working correctly. I am not sure how to fix this method.
> How can I display the album title to the appropriate image?
>
> class ImageAdmin(admin.ModelAdmin):
>     search_fields = ["title"]
>     list_display = ["__unicode__", "title", "tags_", "albums_", "created"]
>     list_filter = ["tags", "albums"]
>
> admin.site.register(Image, ImageAdmin)
>
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/fbcaaf06-0dfd-4001-895e-1d9d483e29e3%40googlegroups.com<https://groups.google.com/d/msgid/django-users/fbcaaf06-0dfd-4001-895e-1d9d483e29e3%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAN7tdFRvai_YPVBKeHxmg6emJvtSOUivcng3NwAvRr09TdbL0g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to