Re: lost admin on upgrade to django 1.3
OK, reinstalling this way on mac: http://breakthesystem.org/2009/django-on-snow-leopard/ (using 1.3 instead of 1.1) worked, so my templates are back and everything works as expected... Thanks, W On Fri, Jul 29, 2011 at 10:15 PM, zignorp wrote: > Actually I'm not using virtualenv, I just installed the new version on my > mac > > tar xzvf Django-1.3.tar.gz > cd Django-1.3 > sudo python setup.py install > > and it overwrote the older version in python/2.6/site-packages/django > (I have 1.1 running on my notebook, that's how I checked where the damn > admin templates directory was) > I'm just going to quit my project and reinstall and see what happens. Maybe > I'll install python 2.7 but it's late... > Thanks for the confirmation that I should indeed have that directory. > Wendy > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/django-users/-/yB-1Z3mjbvIJ. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
have to use older versions of django/python
Hello, I've just been told that I have to run my project on the server with django 1.0, python 2.5, when previously I was told I could use any version I wanted, so I've been using python 2.6.1 and django 1.2. Ugh, another wrinkle added to deployment. I think it's possible that it'll work, and I've been asked to test it locally. I'm seeing that I can use virtualenv to switch my python environment, and I'm pretty sure I already have 2.5 installed on my machine, although it's using a newer version of django too. I'm using mostly generic views, it's not a very complicated project and I've looked at documentation to see what might have changed, knock on wood it looks ok. I am using django-sorting and django-pagination, not sure if these will work with the older version. I am pretty new to all this though, so if anyone has any tips that will save me from tearing my hair out, correct order of doing things, etc. I'd really appreciate it. Any advice would be appreciated. Thanks, Wendy -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: error: no module named...
AHA! I've been bitten by that one before. I was fooled by the dash in the way it's named elsewhere. Thanks so much Piotr, looks like that was the problem, and I learned something about the naming of modules. Seems to be behaving now, Wendy On Aug 25, 11:18 am, Piotr Kilczuk wrote: > > Installed /Library/Python/2.6/site-packages/django_sorting-0.1- > > py2.6.egg > > Processing dependencies for django-sorting > > (just specifying 'django-sorting', in installed apps in settings file) > > Are you sure it should be 'django-sorting' not 'django_sorting' (with > underscore)? > > - is a minus in python, so it cannot be used as a name of package/module. > > HTH. > > Regards, > Piotr -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
error: no module named...
Hello, I'm trying to install django-sorting http://github.com/directeur/django-sorting Installed using setup tools: ... Processing django-sorting-0.1.tar.gz Running django-sorting-0.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-OLu5Yy/django-sorting-0.1/egg-dist-tmp-bww4RH Adding django-sorting 0.1 to easy-install.pth file Installed /Library/Python/2.6/site-packages/django_sorting-0.1- py2.6.egg Processing dependencies for django-sorting Finished processing dependencies for django-sorting wendys-mac-pro-3:mysite wendy$ python manage.py runserver Error: No module named django-sorting I do see it in the python path, I'm kind of new to this, but haven't had this problem with the other modules I've set up with setuptools. (I can see working modules right next to this one in my site-packages directory) I then downloaded and installed with setup.py, same error. Checked the init file, it's there, so I'm not sure what to check next. Any help would be greatly appreciated, really wanting to use it! (just specifying 'django-sorting', in installed apps in settings file) Thanks, Wendy -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Ordering in the admin
Thanks Nick, I guess I'll be passing that value, that makes sense. I'm using a generic view to write the list page, I'll read up more on the queries, thanks for all your help, Wendy On Aug 16, 9:55 pm, Nick Serra wrote: > The_film was just sudo code. I was assuming you wanted to show > filmmakers based on a movie id. I would recommend going through the > django tutorials if you haven't, they go over all of the queries and > how the general layout goes when doing stuff like this. > > On Aug 16, 7:46 pm, Wendy wrote: > > > It doesn't know what the_film is: > > name 'the_film' is not defined > > > if I put quotes around 'the_film', it's expecting an integer: > > invalid literal for int() with base 10: 'the_film' > > > I think that what's happening, it's trying to match the id. > > > I'm going to read about filtering a little more, feels like it's > > close... > > (I also tried to put film_id in the parens after filter and got a "too > > many values" error.) > > So much to learn, thanks for all your help, > > Wendy > > > On Aug 16, 4:00 pm, Nick Serra wrote: > > > > In your view do: > > > > filmmakeritems = > > > FilmmakerPosition.objects.filter(film=the_film).order_by('position') > > > > Pass that into your template. Then in your template do: > > > > {% for item in filmmakeritems %} > > > Name: {{ item.filmmaker.first_name }} > > > {% endfor %} > > > > Etc... > > > > On Aug 16, 6:12 pm, Wendy wrote: > > > > > Sure, it's pretty big, here are the relevant fields pulled out: > > > > class Filmmaker (models.Model): > > > > first_name = models.CharField(max_length=30) > > > > last_name = models.CharField(max_length=40) > > > > > def __unicode__(self): > > > > return u'%s %s' % (self.first_name, self.last_name) > > > > > class Film(models.Model): > > > > title = models.CharField(max_length=180) > > > > slug = models.SlugField(unique=True) > > > > #filmmakers = models.ManyToManyField(Filmmaker) > > > > topics = models.ManyToManyField(Topic, blank=True) > > > > > def __unicode__(self): > > > > return self.title > > > > > class FilmmakerPosition(models.Model): > > > > filmmaker = models.ForeignKey(Filmmaker) > > > > film = models.ForeignKey(Film) > > > > position = models.IntegerField() > > > > > -- > > > > > In admin.py: > > > > > class FilmmakerPositionInline(admin.TabularInline): > > > > model = FilmmakerPosition > > > > > class FilmAdmin(admin.ModelAdmin): > > > > inlines = [ > > > > FilmmakerPositionInline, > > > > ] > > > > ... (there's more) > > > > > --- > > > > > Anyway, this was what I was using in my template when filmmakers was a > > > > many to many relationship with film (commented out in the model > > > > stuff): > > > > by {% with film.filmmakers.all as filmmakers %} > > > > {% for filmmaker in filmmakers %} > > > > {% if filmmakers|length > 2 and not > > > > forloop.first %}, {% endif > > > > %} > > > > {% if forloop.last and not forloop.first > > > > %}and {% endif %} > > > > {{filmmaker.first_name }} > > > > {{filmmaker.last_name}} > > > > {% endfor %} > > > > {% endwith %} > > > > > Thanks, > > > > Wendy > > > > > On Aug 16, 2:13 pm, Nick Serra wrote: > > > > > > Can you list your models.py for me? What exactly do you want to show > > > > > in your template? I'm guessing some sort of WHERE clause, like all > > > > > filmmakers for a film or something. > > > > > > On Aug 16, 5:08 pm, Wendy wrote: > > > > > > > OK, I have the inline solution working in the admin, I can see why > > > > > > it's prettier! > > > > > > Now I'm trying to figure out how to refer to these filmmakers in my > > > > > &
Re: Ordering in the admin
It doesn't know what the_film is: name 'the_film' is not defined if I put quotes around 'the_film', it's expecting an integer: invalid literal for int() with base 10: 'the_film' I think that what's happening, it's trying to match the id. I'm going to read about filtering a little more, feels like it's close... (I also tried to put film_id in the parens after filter and got a "too many values" error.) So much to learn, thanks for all your help, Wendy On Aug 16, 4:00 pm, Nick Serra wrote: > In your view do: > > filmmakeritems = > FilmmakerPosition.objects.filter(film=the_film).order_by('position') > > Pass that into your template. Then in your template do: > > {% for item in filmmakeritems %} > Name: {{ item.filmmaker.first_name }} > {% endfor %} > > Etc... > > On Aug 16, 6:12 pm, Wendy wrote: > > > Sure, it's pretty big, here are the relevant fields pulled out: > > class Filmmaker (models.Model): > > first_name = models.CharField(max_length=30) > > last_name = models.CharField(max_length=40) > > > def __unicode__(self): > > return u'%s %s' % (self.first_name, self.last_name) > > > class Film(models.Model): > > title = models.CharField(max_length=180) > > slug = models.SlugField(unique=True) > > #filmmakers = models.ManyToManyField(Filmmaker) > > topics = models.ManyToManyField(Topic, blank=True) > > > def __unicode__(self): > > return self.title > > > class FilmmakerPosition(models.Model): > > filmmaker = models.ForeignKey(Filmmaker) > > film = models.ForeignKey(Film) > > position = models.IntegerField() > > > -- > > > In admin.py: > > > class FilmmakerPositionInline(admin.TabularInline): > > model = FilmmakerPosition > > > class FilmAdmin(admin.ModelAdmin): > > inlines = [ > > FilmmakerPositionInline, > > ] > > ... (there's more) > > > --- > > > Anyway, this was what I was using in my template when filmmakers was a > > many to many relationship with film (commented out in the model > > stuff): > > by {% with film.filmmakers.all as filmmakers %} > > {% for filmmaker in filmmakers %} > > {% if filmmakers|length > 2 and not > > forloop.first %}, {% endif > > %} > > {% if forloop.last and not forloop.first %}and > > {% endif %} > > {{filmmaker.first_name }} > > {{filmmaker.last_name}} > > {% endfor %} > > {% endwith %} > > > Thanks, > > Wendy > > > On Aug 16, 2:13 pm, Nick Serra wrote: > > > > Can you list your models.py for me? What exactly do you want to show > > > in your template? I'm guessing some sort of WHERE clause, like all > > > filmmakers for a film or something. > > > > On Aug 16, 5:08 pm, Wendy wrote: > > > > > OK, I have the inline solution working in the admin, I can see why > > > > it's prettier! > > > > Now I'm trying to figure out how to refer to these filmmakers in my > > > > film list template, as there is no longer a film.filmmakers object... > > > > So when I look in mysql, films_filmmakerposition has an id, a > > > > filmmaker id, a film id and a position. > > > > My Filmmaker Object has a first name and last name. > > > > I'm not sure where to start on this one, any help would be greatly > > > > appreciated. > > > > Thanks, > > > > Wendy > > > > > On Aug 16, 12:45 pm, Wendy wrote: > > > > > > Thanks, Nick, I just figured that out, doh! So I got the first > > > > > example going, I guess I'll try the inline solution as well, if it's > > > > > the pretty way to do it... It'll be good for me to actually see what > > > > > they both do. > > > > > W > > > > > > On Aug 16, 12:28 pm, Nick Serra wrote: > > > > > > > The inline solution is the pretty way to do it. If you just want the > > > > > > join to show up in the admin, then simply register the join model in > > > > > > the admin like any other model. In your admin,py include > > > > > >
Re: Ordering in the admin
Sure, it's pretty big, here are the relevant fields pulled out: class Filmmaker (models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=40) def __unicode__(self): return u'%s %s' % (self.first_name, self.last_name) class Film(models.Model): title = models.CharField(max_length=180) slug = models.SlugField(unique=True) #filmmakers = models.ManyToManyField(Filmmaker) topics = models.ManyToManyField(Topic, blank=True) def __unicode__(self): return self.title class FilmmakerPosition(models.Model): filmmaker = models.ForeignKey(Filmmaker) film = models.ForeignKey(Film) position = models.IntegerField() -- In admin.py: class FilmmakerPositionInline(admin.TabularInline): model = FilmmakerPosition class FilmAdmin(admin.ModelAdmin): inlines = [ FilmmakerPositionInline, ] ... (there's more) --- Anyway, this was what I was using in my template when filmmakers was a many to many relationship with film (commented out in the model stuff): by {% with film.filmmakers.all as filmmakers %} {% for filmmaker in filmmakers %} {% if filmmakers|length > 2 and not forloop.first %}, {% endif %} {% if forloop.last and not forloop.first %}and {% endif %} {{filmmaker.first_name }} {{filmmaker.last_name}} {% endfor %} {% endwith %} Thanks, Wendy On Aug 16, 2:13 pm, Nick Serra wrote: > Can you list your models.py for me? What exactly do you want to show > in your template? I'm guessing some sort of WHERE clause, like all > filmmakers for a film or something. > > On Aug 16, 5:08 pm, Wendy wrote: > > > OK, I have the inline solution working in the admin, I can see why > > it's prettier! > > Now I'm trying to figure out how to refer to these filmmakers in my > > film list template, as there is no longer a film.filmmakers object... > > So when I look in mysql, films_filmmakerposition has an id, a > > filmmaker id, a film id and a position. > > My Filmmaker Object has a first name and last name. > > I'm not sure where to start on this one, any help would be greatly > > appreciated. > > Thanks, > > Wendy > > > On Aug 16, 12:45 pm, Wendy wrote: > > > > Thanks, Nick, I just figured that out, doh! So I got the first > > > example going, I guess I'll try the inline solution as well, if it's > > > the pretty way to do it... It'll be good for me to actually see what > > > they both do. > > > W > > > > On Aug 16, 12:28 pm, Nick Serra wrote: > > > > > The inline solution is the pretty way to do it. If you just want the > > > > join to show up in the admin, then simply register the join model in > > > > the admin like any other model. In your admin,py include > > > > FilmmakerPosition and then do admin.site.register(FilmmakerPosition) > > > > > On Aug 16, 3:24 pm, Wendy wrote: > > > > > > Thanks Nick, > > > > > I tried the first solution first. > > > > > You're right, the many to manys aren't editable on that page, but the > > > > > problem is, I'm not seeing another admin page for the new join model: > > > > > > class FilmmakerPosition(models.Model): > > > > > filmmaker = models.ForeignKey(Filmmaker) > > > > > film = models.ForeignKey(Film) > > > > > position = models.IntegerField() > > > > > > > > > > (it is in the db) > > > > > so there's no way I can assign filmmakers to a film in the admin. > > > > > In the Film class it specifies: > > > > > > > > > > filmmakers = models.ManyToManyField(Filmmaker, > > > > > through='FilmmakerPosition') > > > > > > > > > > > Am I missing something? > > > > > > I was slightly more intimidated by the inline example, as I'm not sure > > > > > I want to scrap the many to many relationship. (there are lots of > > > > > films that have multiple filmmakers and vice versa, and I'd like to be > > > > > able to list them on both ends) I'm still trying to wrap my head > > > > > around how I could do that wi
Re: Ordering in the admin
OK, I have the inline solution working in the admin, I can see why it's prettier! Now I'm trying to figure out how to refer to these filmmakers in my film list template, as there is no longer a film.filmmakers object... So when I look in mysql, films_filmmakerposition has an id, a filmmaker id, a film id and a position. My Filmmaker Object has a first name and last name. I'm not sure where to start on this one, any help would be greatly appreciated. Thanks, Wendy On Aug 16, 12:45 pm, Wendy wrote: > Thanks, Nick, I just figured that out, doh! So I got the first > example going, I guess I'll try the inline solution as well, if it's > the pretty way to do it... It'll be good for me to actually see what > they both do. > W > > On Aug 16, 12:28 pm, Nick Serra wrote: > > > The inline solution is the pretty way to do it. If you just want the > > join to show up in the admin, then simply register the join model in > > the admin like any other model. In your admin,py include > > FilmmakerPosition and then do admin.site.register(FilmmakerPosition) > > > On Aug 16, 3:24 pm, Wendy wrote: > > > > Thanks Nick, > > > I tried the first solution first. > > > You're right, the many to manys aren't editable on that page, but the > > > problem is, I'm not seeing another admin page for the new join model: > > > > class FilmmakerPosition(models.Model): > > > filmmaker = models.ForeignKey(Filmmaker) > > > film = models.ForeignKey(Film) > > > position = models.IntegerField() > > > > > > (it is in the db) > > > so there's no way I can assign filmmakers to a film in the admin. > > > In the Film class it specifies: > > > > > > filmmakers = models.ManyToManyField(Filmmaker, > > > through='FilmmakerPosition') > > > > > > > Am I missing something? > > > > I was slightly more intimidated by the inline example, as I'm not sure > > > I want to scrap the many to many relationship. (there are lots of > > > films that have multiple filmmakers and vice versa, and I'd like to be > > > able to list them on both ends) I'm still trying to wrap my head > > > around how I could do that with this example. > > > > If anyone has anything else to add that would help me understand it > > > better, I'd really appreciate it. > > > > Thanks, > > > Wendy > > > > On Aug 13, 10:03 am, Nick Serra wrote: > > > > > You can go two directions with this. First, you could use a > > > > intermediate model for the many to many join, which would allow you to > > > > specify extra field on the join, in this case the order. Read up on > > > > this > > > > here:http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-o... > > > > > The problem with solution one is that the many to many won't be > > > > editable on that page anymore. > > > > > Solution two would be to scrap the manytomany and use inline models > > > > instead. You would make an intermediate model, say FilmmakerItem, > > > > which would foreign key to the model you want to join to, and a > > > > foreign key to the filmmaker, and would have a field for order. This > > > > would be editable in the admin under the same page. > > > > > Read about inline > > > > here:http://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodelad... > > > > > On Aug 13, 12:52 pm, Wendy wrote: > > > > > > I have a many to many field, with the horizontal available and chosen > > > > > boxes in the admin. I wanted to see if there's any way that an admin > > > > > can select the order that the chosen objects show up, and have it be > > > > > saved and display that way. Right now, they're not ordered, but seem > > > > > to show up based on when the object was created. So I'm choosing > > > > > filmmakers for a film, and the only way I can change the order is to > > > > > destroy the filmmaker objects, then recreate and add them in a > > > > > different order, something that obviously wouldn't work in the real > > > > > world. Is there any way to save the order in the chosen box in the > > > > > admin? > > > > > > Thanks, > > > > > Wendy -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Ordering in the admin
Thanks, Nick, I just figured that out, doh! So I got the first example going, I guess I'll try the inline solution as well, if it's the pretty way to do it... It'll be good for me to actually see what they both do. W On Aug 16, 12:28 pm, Nick Serra wrote: > The inline solution is the pretty way to do it. If you just want the > join to show up in the admin, then simply register the join model in > the admin like any other model. In your admin,py include > FilmmakerPosition and then do admin.site.register(FilmmakerPosition) > > On Aug 16, 3:24 pm, Wendy wrote: > > > Thanks Nick, > > I tried the first solution first. > > You're right, the many to manys aren't editable on that page, but the > > problem is, I'm not seeing another admin page for the new join model: > > > class FilmmakerPosition(models.Model): > > filmmaker = models.ForeignKey(Filmmaker) > > film = models.ForeignKey(Film) > > position = models.IntegerField() > > > > (it is in the db) > > so there's no way I can assign filmmakers to a film in the admin. > > In the Film class it specifies: > > > > filmmakers = models.ManyToManyField(Filmmaker, > > through='FilmmakerPosition') > > > > > Am I missing something? > > > I was slightly more intimidated by the inline example, as I'm not sure > > I want to scrap the many to many relationship. (there are lots of > > films that have multiple filmmakers and vice versa, and I'd like to be > > able to list them on both ends) I'm still trying to wrap my head > > around how I could do that with this example. > > > If anyone has anything else to add that would help me understand it > > better, I'd really appreciate it. > > > Thanks, > > Wendy > > > On Aug 13, 10:03 am, Nick Serra wrote: > > > > You can go two directions with this. First, you could use a > > > intermediate model for the many to many join, which would allow you to > > > specify extra field on the join, in this case the order. Read up on > > > this > > > here:http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-o... > > > > The problem with solution one is that the many to many won't be > > > editable on that page anymore. > > > > Solution two would be to scrap the manytomany and use inline models > > > instead. You would make an intermediate model, say FilmmakerItem, > > > which would foreign key to the model you want to join to, and a > > > foreign key to the filmmaker, and would have a field for order. This > > > would be editable in the admin under the same page. > > > > Read about inline > > > here:http://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodelad... > > > > On Aug 13, 12:52 pm, Wendy wrote: > > > > > I have a many to many field, with the horizontal available and chosen > > > > boxes in the admin. I wanted to see if there's any way that an admin > > > > can select the order that the chosen objects show up, and have it be > > > > saved and display that way. Right now, they're not ordered, but seem > > > > to show up based on when the object was created. So I'm choosing > > > > filmmakers for a film, and the only way I can change the order is to > > > > destroy the filmmaker objects, then recreate and add them in a > > > > different order, something that obviously wouldn't work in the real > > > > world. Is there any way to save the order in the chosen box in the > > > > admin? > > > > > Thanks, > > > > Wendy -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Ordering in the admin
Thanks Nick, I tried the first solution first. You're right, the many to manys aren't editable on that page, but the problem is, I'm not seeing another admin page for the new join model: class FilmmakerPosition(models.Model): filmmaker = models.ForeignKey(Filmmaker) film = models.ForeignKey(Film) position = models.IntegerField() (it is in the db) so there's no way I can assign filmmakers to a film in the admin. In the Film class it specifies: filmmakers = models.ManyToManyField(Filmmaker, through='FilmmakerPosition') Am I missing something? I was slightly more intimidated by the inline example, as I'm not sure I want to scrap the many to many relationship. (there are lots of films that have multiple filmmakers and vice versa, and I'd like to be able to list them on both ends) I'm still trying to wrap my head around how I could do that with this example. If anyone has anything else to add that would help me understand it better, I'd really appreciate it. Thanks, Wendy On Aug 13, 10:03 am, Nick Serra wrote: > You can go two directions with this. First, you could use a > intermediate model for the many to many join, which would allow you to > specify extra field on the join, in this case the order. Read up on > this > here:http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-o... > > The problem with solution one is that the many to many won't be > editable on that page anymore. > > Solution two would be to scrap the manytomany and use inline models > instead. You would make an intermediate model, say FilmmakerItem, > which would foreign key to the model you want to join to, and a > foreign key to the filmmaker, and would have a field for order. This > would be editable in the admin under the same page. > > Read about inline > here:http://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodelad... > > On Aug 13, 12:52 pm, Wendy wrote: > > > I have a many to many field, with the horizontal available and chosen > > boxes in the admin. I wanted to see if there's any way that an admin > > can select the order that the chosen objects show up, and have it be > > saved and display that way. Right now, they're not ordered, but seem > > to show up based on when the object was created. So I'm choosing > > filmmakers for a film, and the only way I can change the order is to > > destroy the filmmaker objects, then recreate and add them in a > > different order, something that obviously wouldn't work in the real > > world. Is there any way to save the order in the chosen box in the > > admin? > > > Thanks, > > Wendy -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Ordering in the admin
I have a many to many field, with the horizontal available and chosen boxes in the admin. I wanted to see if there's any way that an admin can select the order that the chosen objects show up, and have it be saved and display that way. Right now, they're not ordered, but seem to show up based on when the object was created. So I'm choosing filmmakers for a film, and the only way I can change the order is to destroy the filmmaker objects, then recreate and add them in a different order, something that obviously wouldn't work in the real world. Is there any way to save the order in the chosen box in the admin? Thanks, Wendy -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Many to many fields to string
Thanks so much both of you, totally works and makes sense. I used Joseph's version because of the commas, but they both helped me understand what was happening. I notice that it seems to be ok to put the if statement on one line: {% if filmmakers|length > 2 and not forloop.first %}, {% endif %} is that generally ok, or do I want to indent everything and balance the if/endif statements? Thanks again, Wendy On Aug 11, 3:18 pm, Joseph Spiros wrote: > You'll want to loop through the objects and print the appropriate > property of the objects that consists of just the name. Here's some > template code that does that, and also separates with commas and "and", > using a serial comma (aka Oxford comma). > > (This assumes that your Filmmaker model has a "name" property/field) > > {% with film.filmmakers.all as filmmakers %}{% for filmmaker in > filmmakers %}{% if filmmakers|length > 2 and not forloop.first %}, {% > endif %}{% if forloop.last and not forloop.first %} and {% endif %}{{ > filmmaker.name }}{% endfor %} > > Hope that helps! > > On 8/11/10 3:53 PM, Wendy wrote: > > > > > Hello, > > I'm just getting started, and I'm returning a many to many object in > > my template: > > > p>{{ film.filmmakers.all }} > > > So it's displaying the list: > > > [, ] > > > Can anyone tell me how to return just a string of the names? > > I'm still getting acclimated to python syntax. > > > Actually in a perfect world, it would be great to concatenate the > > names, and add an 'and' b4 the last one, I imagine this is done > > frequently? > > > Thanks, > > Wendy > > -- > Joseph Spiros > iThink Software > joseph.spi...@ithinksw.com > +1 (440) 707-6855 -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Many to many fields to string
Hello, I'm just getting started, and I'm returning a many to many object in my template: p>{{ film.filmmakers.all }} So it's displaying the list: [, ] Can anyone tell me how to return just a string of the names? I'm still getting acclimated to python syntax. Actually in a perfect world, it would be great to concatenate the names, and add an 'and' b4 the last one, I imagine this is done frequently? Thanks, Wendy -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.