displaying album title for appropriate image (ForiegnKey)
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. For more options, visit https://groups.google.com/d/optout.
admin layout for Gallery app
I want to create me admin like this: http://lightbird.net/dbe/_static/p1.png What I have right now is: def get_upload_file_name(instance, filename): new_file_path_and_name = os.path.join(MEDIA_ROOT,'img/albums') return new_file_path_and_name 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) def tags_(self): lst = [x[1] for x in self.tags.values_list()] return str(join(lst, ", ")) def albums_(self): lst = [x[1] for x in self.albums.values_list()] return str(join(lst, ", ")) def __unicode__(self): return self.image.name class AlbumAdmin(admin.ModelAdmin): search_fields = ["title"] list_display = ["title"] class TagAdmin(admin.ModelAdmin): list_display = ["tag"] class ImageAdmin(admin.ModelAdmin): search_fields = ["title"] list_display = ["__unicode__", "title", "tags_", "albums_", "created"] list_filter = ["tags", "albums"] admin.site.register(Album, AlbumAdmin) admin.site.register(Tag, TagAdmin) admin.site.register(Image, ImageAdmin) I'm not sure what an acceptable input for ImageAdmin's list_display. I'm following the lightbird (http://lightbird.net/dbe/photo.html) tutorial but since it's out of date, I'm making some of my own choices along the way. I'm not sure how to modify my tags_ and albums_ method to achieve the admin layout. -- 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/2836d672-1120-4cc8-863d-276c9122b9e7%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Possible Model Inheritance Issue? Error: [Model_Name] instance needs to have a primary key value before a many-to-many relationship can be used
I know this is a VERY VERY old thread but oh my god I love you, I was having the same problem for the same reason and would have never imaged that was why (though it makes sense). Took me a long time to finally find this thread. On Thursday, January 22, 2009 1:38:57 AM UTC-2, Keyton Weissinger wrote: > > OK. I figured it out and it was VERY STRANGE. Maybe some one reading > this can tell me WWWHHHYYY my solution works. For now, it's voodoo to > me... > > Turns out that some of my code (in the view where I was having > trouble) called some code that looked sort of like this: > > field_list = model._meta.fields > field_list.extend(model._meta.many_to_many) > for field in field_list: > related_model_name = None > related_model_app_name = None > if (not field.name[-4:] == '_ptr') and (not field.__class__ == > AutoField): > > if issubclass(field.__class__, related.RelatedField): > if not field.__class__ == related.ForeignKey: > related_model_app_name = field.rel.to.__module__.split > ('.')[0] > # We'll ignore all django-specific models (such as > User, etc). > if not related_model_app_name == 'django': > related_model_name = field.rel.to.__name__ > full_related_model_name = '.'.join > ([field.rel.to.__module__, related_model_name]) > relation_tuple_list.append((full_model_name > +'%relation'+field.name+'%' + full_related_model_name, \ > 'Mapping: ' + > model.__name__ + '-' + \ > related_model_name)) > else: > continue > > It is just pulling together a list of relationships between two > models. I'm not using these models to actually DO anything. Just what > you see. > > I could go to the command line and do the following: > >>> from batchimport.forms import ImportOptionsForm > >>> from sbase.models import Student > >>> mydict = {'city': u'Columbus', 'first_name': u'Jimmy', 'last_name': > u'Jones', 'zip': 43215.0, 'title': u'Mr.', 'dob': '1956-12-29', > 'phone_primary': u'614-468-5940', 'state': u'OH', 'address': u'142, Quilly > Lane', 'type': u'Student', 'email': u'miles...@spambob.com '} > > >>> mystudent = Student(**mydict) > > The import of ImportOptionsForms, it turns out, called the above code. > > OK. The above series of commands would fail every time with the > following error. > 'Student' instance needs to have a primary key value before a many-to- > many relationship can be used. > > I was close. I could repeat my strange in-app problem on the command > line. Yea. > > So after a LONG time of messing with it, it turns out that django > didn't like how I was handling the many-to-many fields > (model._meta.many_to_many). > > But I was able to fix my problem by just doing this: > > for field_list in [model._meta.fields, model._meta.many_to_many]: > for field in field_list: > related_model_name = None > related_model_app_name = None > if (not field.name[-4:] == '_ptr') and (not > field.__class__ == AutoField): > > if issubclass(field.__class__, related.RelatedField): > if not field.__class__ == related.ForeignKey: > related_model_app_name = > field.rel.to.__module__.split('.')[0] > # We'll ignore all django-specific models > (such as User, etc). > if not related_model_app_name == 'django': > related_model_name = field.rel.to.__name__ > full_related_model_name = '.'.join > ([field.rel.to.__module__, related_model_name]) > relation_tuple_list.append((full_model_name > +'%relation'+field.name+'%' + full_related_model_name, \ > 'Mapping: ' + > model.__name__ + '-' + \ > > related_model_name)) > else: > continue > > YEAH! That's all I changed. Instead of extending my list of fields > with the many_to_many fields, I just iterated over one (to get the > ForeignKey relationships etc, and then I subsequently iterated over my > many-to-many fields. > > Why (the HELL) does the first version trigger this error: > 'Student' instance needs to have a primary key value before a many-to- > many relationship can be used. > > But the second version doesn't? > > If I'm an idiot, PLEASE tell me how so, because I'd really like to > avoid this kind of quagmire if I can > > Thank you VERY MUCH Martin and Malcolm. I appreciate your respective > looks at this problem very much. Your taking time to help with this > kind of thorny issue is what makes this community rock and, frankly, > inspires me to help out more. > > Keyton > > On Jan 21, 3:5
GET parameters in admin "add" model page
I noticed that django admin "add" page reads GET parameters and uses them as initial values in the form. However I was not able to pass DateTime values in this way. In particular if I try to pass a DateTime value I get a "server error". See http://stackoverflow.com/questions/23559771/django-admin-add-page-initial-datetime-from-get-parameters for more details. 1. is it possible to pass DateTime values this way? 2. isn't it a bug if a user is able to generate a server error by messing with GET parameters? thanks E. -- 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/4021a36d-81d2-41ff-a160-f04fe0fc8513%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
List Filter Age range
Hi there. I'm having a problem with filter a model by age range, is a DateField but in the html I would like 2 input text to type ages. So far I only see filter by list not input text. Any ideas? -- Anderson Dias Borges Senior Analyst Developer Tu cumprirás o desejo do meu coração se eu Te buscar... I can't see but I'll take my chances To hear You call my name -- 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/CAAin48UUxE%3DFF91guC6OYxP9%3DNLRLgBseXPM_r8oR8O6Equb7Q%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: Registration in 1.8
What's the value in starting with 1.4? I'd start with the current release - 1.6.4 -- 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/2ad2a303-d6b6-49ff-b194-7e8aa0296d57%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.