filter_horizontal ordering
Hello, I use a couple of filter_horizontals in my admin but cannot figure out how to get the data in them sorted alphabetically. Here is my code: class PlaceAdmin(admin.ModelAdmin): list_display = ('place_name', 'area', 'subway',) filter_horizontal = ('labels', 'cuisine', 'category',) ordering = ['place_name'] class LabelAdmin(admin.ModelAdmin): list_display = ('label_name',) ordering = ['label_name'] class CuisineAdmin(admin.ModelAdmin): list_display = ('cuisine_name',) ordering = ['cuisine_name'] class CategoryAdmin(admin.ModelAdmin): list_display = ('category_name',) ordering = ['category_name'] Say, for an example that I want the labels to be displayed in alphabetical order; how would I do this? Or if I just want all my filter_horizontal displays to be in order? Thanks, Nicklas -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: NameError help
Never mind. Too tired to realize I had my model classes in the wrong order. On Tue, Mar 19, 2013 at 1:18 AM, Nicklas af Ekenstam wrote: > Hello, > > I am working on a few models but keep getting "NameError: name 'Area' > is not defined" while trying to validate. I must be doing something > wrong but I seem to be unable to figure it out myself and any help > would be very appreciated as I am now stuck on what I believe is a > really trivial problem. > > The application is called restaurants and here is my models.py: > > from django.db import models > from geoposition.fields import GeopositionField > > # Create your models here. > class Restaurant(models.Model): > PRICES = ( > ('$', '$'), > ('$$', '$$'), > ('$$$', '$$$'), > ('', ''), > ('$', '$$'), > ('unknown', 'Unknown'), > ) > restaurant_name = models.CharField(max_length=100) > description = models.TextField(blank=True) > area = models.ForeignKey(Area) > labels = models.ManyToManyField(Label) > cuisine = models.ManyToManyField(Cuisine) > price_range = models.CharField(max_length=10, choices=PRICES) > phone = models.CharField(max_length=100,blank=True) > address = models.TextField() > subway = models.ForeignKey(Subway, blank=True) > subway_distance = models.CharField(max_length=100, blank=True) > opening_hours = models.TextField(blank=True) > payment_methods = models.ForeignKey(Payment, blank=True) > website_url = models.URLField(blank=True) > email = models.EmailField(blank=True) > position = GeopositionField() > publication_date = models.DateField() > def __unicode__(self): > return self.restaurant_name > > class Area(models.Model): > area_name = models.CharField(max_length=100) > area_name_chinese = models.CharField(max_length=100) > def __unicode__(self): > return self.area_name > > class Label(models.Model): > label_name = models.CharField(max_length=100) > def __unicode__(self): > return self.label_name > > class Cuisine(models.Model): > cuisine_name = models.CharField(max_length=100) > def __unicode__(self): > return self.cuisine_name > > class Payment(models.Model): > payment_name = models.CharField(max_length=100) > def __unicode__(self): > return self.payment_name > > class Subway(models.Model): > subway_name = models.CharField(max_length=100) > subway_name_chinese = models.CharField(max_length=100, blank=True) > def __unicode__(self): > return self.subway_name > > I am trying to hook this up with the admin interface using an admin.py > file that looks like this: > > from django.contrib import admin > from shanghai.restaurants.models import Label, Payment, Area, > Restaurant, Subway, Cuisine > > class LabelAdmin(admin.ModelAdmin): > list_display = ('label_name',) > ordering = ['label_name'] > > class PaymentAdmin(admin.ModelAdmin): > list_display = ('payment_name',) > ordering = ['payment_name'] > > class AreaAdmin(admin.ModelAdmin): > list_display = ('area_name',) > ordering = ['area_name'] > > class RestaurantAdmin(admin.ModelAdmin): > list_display = ('restaurant_name', 'area', 'publication_date',) > ordering = ['publication_date'] > > class SubwayAdmin(admin.ModelAdmin): > list_display = ('subway_name',) > ordering = ['subway_name'] > > class CuisineAdmin(admin.ModelAdmin): > list_display = ('cuisine_name',) > ordering = ['cuisine_name'] > > admin.site.register(Label, LabelAdmin) > admin.site.register(Payment, PaymentAdmin) > admin.site.register(Area, AreaAdmin) > admin.site.register(Restaurant, RestaurantAdmin) > admin.site.register(Subway, SubwayAdmin) > admin.site.register(Cuisine, CuisineAdmin) > > Any ideas? Thanks! > > - Nicklas -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
NameError help
Hello, I am working on a few models but keep getting "NameError: name 'Area' is not defined" while trying to validate. I must be doing something wrong but I seem to be unable to figure it out myself and any help would be very appreciated as I am now stuck on what I believe is a really trivial problem. The application is called restaurants and here is my models.py: from django.db import models from geoposition.fields import GeopositionField # Create your models here. class Restaurant(models.Model): PRICES = ( ('$', '$'), ('$$', '$$'), ('$$$', '$$$'), ('', ''), ('$', '$$'), ('unknown', 'Unknown'), ) restaurant_name = models.CharField(max_length=100) description = models.TextField(blank=True) area = models.ForeignKey(Area) labels = models.ManyToManyField(Label) cuisine = models.ManyToManyField(Cuisine) price_range = models.CharField(max_length=10, choices=PRICES) phone = models.CharField(max_length=100,blank=True) address = models.TextField() subway = models.ForeignKey(Subway, blank=True) subway_distance = models.CharField(max_length=100, blank=True) opening_hours = models.TextField(blank=True) payment_methods = models.ForeignKey(Payment, blank=True) website_url = models.URLField(blank=True) email = models.EmailField(blank=True) position = GeopositionField() publication_date = models.DateField() def __unicode__(self): return self.restaurant_name class Area(models.Model): area_name = models.CharField(max_length=100) area_name_chinese = models.CharField(max_length=100) def __unicode__(self): return self.area_name class Label(models.Model): label_name = models.CharField(max_length=100) def __unicode__(self): return self.label_name class Cuisine(models.Model): cuisine_name = models.CharField(max_length=100) def __unicode__(self): return self.cuisine_name class Payment(models.Model): payment_name = models.CharField(max_length=100) def __unicode__(self): return self.payment_name class Subway(models.Model): subway_name = models.CharField(max_length=100) subway_name_chinese = models.CharField(max_length=100, blank=True) def __unicode__(self): return self.subway_name I am trying to hook this up with the admin interface using an admin.py file that looks like this: from django.contrib import admin from shanghai.restaurants.models import Label, Payment, Area, Restaurant, Subway, Cuisine class LabelAdmin(admin.ModelAdmin): list_display = ('label_name',) ordering = ['label_name'] class PaymentAdmin(admin.ModelAdmin): list_display = ('payment_name',) ordering = ['payment_name'] class AreaAdmin(admin.ModelAdmin): list_display = ('area_name',) ordering = ['area_name'] class RestaurantAdmin(admin.ModelAdmin): list_display = ('restaurant_name', 'area', 'publication_date',) ordering = ['publication_date'] class SubwayAdmin(admin.ModelAdmin): list_display = ('subway_name',) ordering = ['subway_name'] class CuisineAdmin(admin.ModelAdmin): list_display = ('cuisine_name',) ordering = ['cuisine_name'] admin.site.register(Label, LabelAdmin) admin.site.register(Payment, PaymentAdmin) admin.site.register(Area, AreaAdmin) admin.site.register(Restaurant, RestaurantAdmin) admin.site.register(Subway, SubwayAdmin) admin.site.register(Cuisine, CuisineAdmin) Any ideas? Thanks! - Nicklas -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.