Re: no attribute 'save_m2m'
On Jan 18, 10:01 am, GoSantoni wrote: > Hi > > Trying to use save_m2m as described > herehttp://docs.djangoproject.com/en/1.0/topics/forms/modelforms/#the-sav... > Though in run into an attrribute error 'Post' object has no attribute > 'save_m2m' > > *** Model *** > class Post(models.Model): > id = models.AutoField(primary_key=True) > imagepost = models.ManyToManyField(Image, verbose_name=_ > ('media')) > > def save(self, force_insert=False, force_update=False): > self.updated_at = datetime.now() > super(Post, self).save(force_insert, force_update) > > *** View *** > def new(request, form_class=BlogForm, template_name="blog/new.html"): > if request.method == "POST": > if request.POST["action"] == "create": > blog_form = form_class(request.user, request.POST) > if blog_form.is_valid(): > blog = blog_form.save(commit=False) > blog.author = request.user > if getattr(settings, 'BEHIND_PROXY', False): > blog.creator_ip = request.META > ["HTTP_X_FORWARDED_FOR"] > else: > blog.creator_ip = request.META['REMOTE_ADDR'] > blog.save() > blog.save_m2m() > request.user.message_set.create(message=_ > ("Successfully saved post '%s'") % blog.item) > if notification: > if blog.status == 2: # published > if friends: # @@@ might be worth having a > shortcut for sending to all friends > notification.send((x['friend'] for x in > Friendship.objects.friends_for_user(blog.author)), "blog_friend_post", > {"post": blog}) > > return HttpResponseRedirect(reverse > ("blog_list_yours")) > else: > blog_form = form_class() > else: > blog_form = form_class(request.user) > > return render_to_response(template_name, { > "blog_form": blog_form, > > }, context_instance=RequestContext(request)) > > Question 1: > So far i found these 2 posts using map and instances in the view. Is > that the way to solve > this?http://stackoverflow.com/questions/1477319/how-to-get-the-django-curr...http://haineault.com/blog/101/ > > Question 2: > Does the def save() in the model need alteration? Or addition of a def > save_m2m() ? Change gives a 'super' object has no attribute 'save_m2m' > > Thanks >From the link you provided. "[..] To work around this problem, every time you save a form using commit=False, Django adds a save_m2m() method to your ModelForm subclass." Try adding blog.save(commit=False) instead of just blog.save() -- 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: import json data into my django app
On Jan 17, 4:58 pm, lance wrote: > Python/Django newbie question: > > I need to create a cron job that fetches json data from a URL, parses > it (presumably using simplejson) and then load the data into my > database using the Django models I've defined. > > I'm having trouble finding any tips, examples, or documentation on how > to do this... any help is greatly appreciated. I did something similar using the delicious api and elementtree to parse the data. First I created a module called utils.py in my application package and wrote a script for grabbing the url, parsing the data and updating the database. Then I created another script called cron.py to run the utils.py every so often. In the cron script you'll have to set your environmental variables for your project like so. import os import sys import site site.addsitedir('/opt/pythonenv/example.com/lib/python2.5/site- packages') # virtual environment sys.path.append('/var/www/vhosts/example.com/') # project location os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings' # settings file # import your module and then call it As far as using simplejson goes I haven't used it before. -- 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: #django :You need to be identified to join that channel
You probably have to register your Nickname with nickserv. http://oreillynet.com/pub/h/1940 On Jan 16, 7:59 am, NMarcu wrote: > Hello, > > Somebody know why i get this message when I try to join django > channel from freenode irc: > #django :You need to be identified to join that channel -- 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: newbie questions regarding models and admin
The philosophy of the admin app is that it is a simple CRUD interface for trusted staff members to manage data. If you need data entry for non staff members (i.e. people you do not trust with the admin) you should create public facing forms and setup some permissions for the users to be able to use them. As for you second question it sounds like you need two models, one for experiment_x and one for sub_experiment_x with a foreignkey to experiment_x. You could probably use inline formsets to generate the extra 8 forms. I'm not sure how you would limit the inline formsets though to exactly 8. Hope this helps. On Nov 24, 5:33 am, Andreas Kuntzagk wrote: > Hi, > > I'm quite new to django and very new to this list. > I'm in the process of writing a small webapp for our lab. > Working with the tutorial I already put together a small model and some > admin pages. > But now I came to some stumbling blocks: > > First is a broader question: I'm wondering what belongs to an admin page > and what should be in a "normal" form. I want to keep track on some > experiments so some (authenticated) users should create experiment > entries and add comments etc. And then I have "machines" where these > experiments run. These don't change so often. So does setting these > things belong into the admin area? > > Second experiments of type x always consist of 8 parallel > subexperiments. How do I model this? These subexperiments should > (automagically) be named subexp1 to subexp8. > > Regards, Andreas -- 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: Per-object permissions
You should look into django-authority. I'm pretty sure that has per- object-permissions. http://packages.python.org/django-authority/index.html On Nov 24, 7:00 am, gamliel roi wrote: > Hello all, > > I have the admin site up and running but I need to create a group of users, > such that each of the users will be able to edit objects that are only > relevant to them (e.g Project objects that the user is also the > ProjectManager). > > I know that in the past Django had a Per-object permissions branch, which is > now abandoned. > > Should I peruse this direction and try to incorporate this branch to my > current code? is it documented and running properly? > > Any other ideas/suggestions/resources regarding this problem? > > -- > Best > Roi Gamliel -- 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.
Recursive ManyToMany?
I'm trying to create a record label website and I'm modeling the music data. I have artists, albums, tracks so far. What I'd like to do is use the artists model for both individual recording artists and groups of recording artists. I'd like to be able to find any singular artist or groups of artists by visiting one URL /artists/artist_slug and be able to view the related artists if there's a artist.artist_set. Any ideas about how I can achieve this using Django? Keep in mind an artist could be in more than one band at once, the reason I put recursive many to many in the title. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Querysets and includes
How would I go about getting a queryset into an include? Say I have a blog and I have a page for the post detail. On the sidebar I would like to have the blog categories dynamically built or have recent articles, or recent comments, etc... What would be the best approach to build these "widgets" for use on multiple pages? Any help would be much appreciated. Thanks. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
problems with post_save and sites framework
I've been setting trying to set up a tumblelog using the sites framework and the current site manager and I'm hitting a bug in either my code or Django's not sure which. Basically what's happening is the first time I save an object the tumble item is created, but the site field is not populated so it will not show up on any site. The second time I save an object the site field is then populated and the tumble item shows up on the appropriate site. I'm not sure what's going on here, but it's driving me nuts. Any ideas? from django.db import models from django.contrib.contenttypes import generic from django.template.loader import render_to_string from django.db.models import signals from django.contrib.contenttypes.models import ContentType from django.contrib.sites.models import Site from django.contrib.sites.managers import CurrentSiteManager from posts.models import * class TumbleItem(models.Model): content_type = models.ForeignKey(ContentType) object_id= models.PositiveIntegerField() pub_date = models.DateTimeField() site = models.ManyToManyField(Site) objects = models.Manager() on_site = CurrentSiteManager() content_object = generic.GenericForeignKey('content_type', 'object_id') def get_rendered_html(self): template_name = 'tumblelog/includes/tumble_item_%s.html' % (self.content_type.name) return render_to_string(template_name, { 'object': self.content_object }) def create_tumble_item(sender, instance, signal, *args, **kwargs): # Check to see if the object was just created for the first time if 'created' in kwargs: if kwargs['created']: create = True # Get the instance's content type ctype = ContentType.objects.get_for_model(instance) site = instance.site pub_date = instance.publish if instance.status == 1: create = False if create: ti, created = TumbleItem.objects.get_or_create(content_type=ctype, object_id=instance.id, pub_date=pub_date) for s in site.all(): ti.site.add(s) else: create = True # Get the instance's content type ctype = ContentType.objects.get_for_model(instance) pub_date = instance.publish site = instance.site if instance.status == 1: create = False if create: ti, created = TumbleItem.objects.get_or_create(content_type=ctype, object_id=instance.id, pub_date=pub_date) for s in site.all(): ti.site.add(s) # Send a signal on post_save for each of these models for Post in [Article, Audio, Video, Download, Quote, Photo, Link, Snippet]: models.signals.post_save.connect(create_tumble_item, sender=Post) --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
get_next_by_FOO(**kwargs) and get_previous_by_FOO(**kwargs) with on_site
I'm wondering if it's possible to use the current site manager with these two functions or if I'm going to have to write my own? def get_previous_post(self): return self.get_previous_by_publish(status__gte=2) def get_next_post(self): return self.get_next_by_publish(status__gte=2) Has anyone had any success I can't seem to get it to work like this. def get_previous_post(self): return self.on_site.get_previous_by_publish(status__gte=2) If I do end up having to write my own function, how would I go about doing that? Thanks. Charlie --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Using ManytoManyField's in signals
On Sep 3, 4:08 pm, Rajesh Dhawan <[EMAIL PROTECTED]> wrote: > On Sep 3, 3:59 pm, nek4life <[EMAIL PROTECTED]> wrote: > > > I'm using Django Beta 2 > > If, instead of top-posting, you bottom-post your responses, it's > easier for people to see which questions you're responding to. > > > > > > > > > Here is my article model > > > from django.db import models > > from django.contrib.sites.models import Site > > from django.contrib.sites.managers import CurrentSiteManager > > from django.contrib import admin > > from django.contrib.auth.models import User > > > class Article(models.Model): > > """Article Model""" > > STATUS_CHOICES = ( > > (1, 'Draft'), > > (2, 'Public'), > > ) > > title = models.CharField(max_length=200) > > slug = models.SlugField() > > author = models.ForeignKey(User, blank=True, null=True) > > lead = models.TextField() > > lead_image = models.FileField(upload_to="lead_images", > > blank=True) > > body = models.TextField() > > site = models.ManyToManyField(Site) > > on_site = CurrentSiteManager() > > status = models.IntegerField(choices=STATUS_CHOICES, > > default=1) > > allow_comments = models.BooleanField(default=True) > > publish = models.DateTimeField() > > created = models.DateTimeField(auto_now_add=True) > > modified = models.DateTimeField(auto_now=True) > > > def __unicode__(self): > > return '%s' % self.title > > > class Meta: > > verbose_name = ('article') > > verbose_name_plural = ('articles') > > Ah, I previously assumed that Article.site is a ForeignKey. See if you > had named it 'sites', it would've been easier to guess? > > Anyway, change that previous ti.site.add(site) snippet to: > > for s in site: > ti.site.add(s) > > You could also try: > ti.site = site > > But that will wipe out any previous values of site you may have > associated with the same ti instance. > > -RD Sorry about top posting. This is about the 3rd time I've used google groups before, but what you're saying makes sense. I'm sure I'll have many more questions to get the hang of it! for s in site: ti.site.add(s) almost worked. I got an error that the ManyRelatedManager wasn't iterable. So I did a little research and found that for s in site.all(): ti.site.add(s) that works because the query set that it builds is iterable. so that final snippet looked like this. ti, created = TumbleItem.objects.get_or_create(content_type=ctype, object_id=instance.id, pub_date=pub_date) for s in site.all(): ti.site.add(s) Thanks a ton. You've been a huge help. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Using ManytoManyField's in signals
I'm using Django Beta 2 This is my post data bodyu'body' status u'2' allow_comments u'on' _save u'Save' leadu'lead' author u'1' title u'Test Post' siteu'2' publish_1 u'15:04:22' publish_0 u'2008-09-03' lead_image u'' slugu'test' Here is my article model from django.db import models from django.contrib.sites.models import Site from django.contrib.sites.managers import CurrentSiteManager from django.contrib import admin from django.contrib.auth.models import User class Article(models.Model): """Article Model""" STATUS_CHOICES = ( (1, 'Draft'), (2, 'Public'), ) title = models.CharField(max_length=200) slug = models.SlugField() author = models.ForeignKey(User, blank=True, null=True) lead = models.TextField() lead_image = models.FileField(upload_to="lead_images", blank=True) body = models.TextField() site = models.ManyToManyField(Site) on_site= CurrentSiteManager() status = models.IntegerField(choices=STATUS_CHOICES, default=1) allow_comments = models.BooleanField(default=True) publish= models.DateTimeField() created= models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) def __unicode__(self): return '%s' % self.title class Meta: verbose_name= ('article') verbose_name_plural = ('articles') On Sep 3, 3:31 pm, Rajesh Dhawan <[EMAIL PROTECTED]> wrote: > > Seems like I'm headed in the right direction, I made the changes you > > suggested but now I'm getting a warning. > > > > > Exception Type: Warning at /admin/posts/article/add/ > > Exception Value: Incorrect integer value: > > ' > 0xfd8d50>' for column 'site_id' at row 1 > > > Not sure what's going on... > > I don't know how your Article and other such models are defined, by > are you guaranteed to have a valid Site instance for instance.site or > can that value be None? If you're in DEBUG mode (settings.DEBUG=True), > you should be able to see the value of 'site' in your browser. If not, > try printing 'site' and 'site.pk' just before you make the site.add() > call. > > Also, what version of Django are you on? > > -Rajesh D --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Using ManytoManyField's in signals
Thanks Rajesh, Seems like I'm headed in the right direction, I made the changes you suggested but now I'm getting a warning. Environment: Request Method: POST Request URL: http://localhost:8000/admin/posts/article/add/ Django Version: 1.0-beta_2-SVN-unknown Python Version: 2.5.2 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin', 'publish.posts', 'publish.tumblelog'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.middleware.doc.XViewMiddleware') Traceback: File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ site-packages/django/core/handlers/base.py" in get_response 86. response = callback(request, *callback_args, **callback_kwargs) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ site-packages/django/contrib/admin/sites.py" in root 173. return self.model_page(request, *url.split('/', 2)) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ site-packages/django/views/decorators/cache.py" in _wrapped_view_func 44. response = view_func(request, *args, **kwargs) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ site-packages/django/contrib/admin/sites.py" in model_page 192. return admin_obj(request, rest_of_url) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ site-packages/django/contrib/admin/options.py" in __call__ 185. return self.add_view(request) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ site-packages/django/db/transaction.py" in _commit_on_success 238. res = func(*args, **kw) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ site-packages/django/contrib/admin/options.py" in add_view 493. self.save_model(request, new_object, form, change=False) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ site-packages/django/contrib/admin/options.py" in save_model 367. obj.save() File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ site-packages/django/db/models/base.py" in save 280. self.save_base(force_insert=force_insert, force_update=force_update) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ site-packages/django/db/models/base.py" in save_base 363. created=(not record_exists), raw=raw) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ site-packages/django/dispatch/dispatcher.py" in send 148. response = receiver(signal=self, sender=sender, **named) File "/Users/nek4life/djcode/publish/../publish/tumblelog/models.py" in create_tumble_item 43. ti.site.add(site) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ site-packages/django/db/models/fields/related.py" in add 374. self._add_items(self.source_col_name, self.target_col_name, *objs) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ site-packages/django/db/models/fields/related.py" in _add_items 446. [self._pk_val, obj_id]) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ site-packages/django/db/backends/util.py" in execute 19. return self.cursor.execute(sql, params) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ site-packages/MySQL_python-1.2.2-py2.5-macosx-10.3-i386.egg/MySQLdb/ cursors.py" in execute 168. if not self._defer_warnings: self._warning_check() File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ site-packages/MySQL_python-1.2.2-py2.5-macosx-10.3-i386.egg/MySQLdb/ cursors.py" in _warning_check 82. warn(w[-1], self.Warning, 3) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ warnings.py" in warn 62. globals) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ warnings.py" in warn_explicit 102. raise message Exception Type: Warning at /admin/posts/article/add/ Exception Value: Incorrect integer value: '' for column 'site_id' at row 1 Not sure what's going on... On Sep 3, 2:45 pm, Rajesh Dhawan <[EMAIL PROTECTED]> wrote: > Hi, > > > > > from django.db import models > > from django.contrib.contenttypes import generic > > from d
Using ManytoManyField's in signals
from django.db import models from django.contrib.contenttypes import generic from django.template.loader import render_to_string from django.db.models import signals from django.contrib.contenttypes.models import ContentType from django.dispatch import dispatcher from django.contrib.sites.models import Site from django.contrib.sites.managers import CurrentSiteManager from publish.posts.models import * class TumbleItem(models.Model): content_type = models.ForeignKey(ContentType) object_id= models.PositiveIntegerField() pub_date = models.DateTimeField() site = models.ManyToManyField(Site) objects = models.Manager() on_site = CurrentSiteManager() content_object = generic.GenericForeignKey('content_type', 'object_id') def get_rendered_html(self): template_name = 'tumblelog/includes/tumble_item_%s.html' % (self.content_type.name) return render_to_string(template_name, { 'object': self.content_object }) def create_tumble_item(sender, instance, signal, *args, **kwargs): # Check to see if the object was just created for the first time if 'created' in kwargs: if kwargs['created']: create = True # Get the instance's content type ctype = ContentType.objects.get_for_model(instance) pub_date = instance.publish site = instance.site if instance.status == 1: create = False if create: ti = TumbleItem.objects.get_or_create(content_type=ctype, object_id=instance.id, pub_date=pub_date, site=site) # Send a signal on post_save for each of these models for Post in [Article, Audio, Video, Download, Quote, Photo, Link, Snippet]: models.signals.post_save.connect(create_tumble_item, sender=Post) Basically I'm getting an error that I can't pass site=site on the post which is a ManyToManyField. I'm trying to make this tumblelog work across a dozen sites. Any ideas? --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: database relationships
Yup that did it. I could have sworn I tried that, but I guess not. Thanks again. Charlie On Aug 27, 1:27 pm, lingrlongr <[EMAIL PROTECTED]> wrote: > Try this is the template: > > {% for albumart in album.albumart_set.all %} > {{ albumart.image }} > {% endfor %} > > On Aug 27, 11:58 am, nek4life <[EMAIL PROTECTED]> wrote: > > > Well this works great while using the generic detail view, but when I > > return a list view the relationships won't work. > > > in my view > > > def album_list(request, page=0): > > return list_detail.object_list( > > request, > > queryset = Album.objects.select_related().all(), > > paginate_by = 20, > > page = page, > > template_object_name = 'album', > > ) > > > in my template > > > {% for albumart in album.albumart_set.all %} > > {{ album.albumart.image }} > > {% endfor %} > > > Is this not supported in list_detail.object_list? I can't find > > information on this anywhere, may have to change my database around. > > > On Aug 22, 11:44 am, nek4life <[EMAIL PROTECTED]> wrote: > > > > Awesome. I got it to work using this code in my view. > > > > def artist_detail(request, slug): > > > album_list = Album.objects.all() > > > return list_detail.object_detail( > > > request, > > > queryset = Artist.objects.all(), > > > slug = slug, > > > template_object_name = 'artist', > > > extra_context={'album_list': album_list} > > > ) > > > > But the way you're doing it only calls the database once instead of > > > twice. Beautiful! Thank you. I'm going to try the query you > > > suggested. > > > > queryset=Artist.objects.select_related().all() > > > > I'd like to just pull in the albums, artwork, and tracks related to > > > the particular artist in the url slug, for > > > instancehttp://www.example.com/artists/artist-name > > > > You've been a huge help. Thanks a ton! > > > > Charlie > > > > On Aug 22, 11:20 am, lingrlongr <[EMAIL PROTECTED]> wrote: > > > > > Also note, if your intentions were to grab all that information and > > > > just send the artist to the template, I think you'd get better > > > > performance if your queryset in the view looked like this: > > > > > queryset=Artist.objects.select_related().all() > > > > > Keith > > > > > On Aug 22, 11:17 am, lingrlongr <[EMAIL PROTECTED]> wrote: > > > > > > Super easy :) Just to show you another way to implement generic > > > > > views, I used custom view that returns a generic view. > > > > > > # urls.py > > > > > from myapp.views import artist > > > > > ... > > > > > (r'^artist/(?P\w+)/$', artist), > > > > > ... > > > > > > #views.py > > > > > from django.views.generic.list_detail import object_detail > > > > > def artist(request, slug): > > > > > return object_detail( > > > > > request, > > > > > queryset=Artist.objects.all(), > > > > > slug = slug, > > > > > template_object_name = 'artist' > > > > > ) > > > > > > # //artist_list.html > > > > > {{ artist }} > > > > > Albums > > > > > > > > > > {% for album in artist.album_set.all %} > > > > > {{ album.name }} > > > > > > > > > > {% for track in album.track_set.all %} > > > > > {{ track.name }} > > > > > {% endfor %} > > > > > > > > > > {% endfor %} > > > > > > > > > > > Django makes traversing relationships easy... > > > > > > HTH > > > > > > Keith > > > > > > On Aug 22, 10:03 am, nek4life <[EMAIL PROTECTED]> wrote: > > > > > > > So if I sent the artist to the template and wanted to grab the list > > > > > > of > > > > > > albums with all the album tracks how would I go about that. Would I > > > > > > have to pull in all the data with a custom view? So far I've only > > > > > > been using generic views. It definitely makes sense pulling in the > > &
Re: database relationships
Well this works great while using the generic detail view, but when I return a list view the relationships won't work. in my view def album_list(request, page=0): return list_detail.object_list( request, queryset = Album.objects.select_related().all(), paginate_by = 20, page = page, template_object_name = 'album', ) in my template {% for albumart in album.albumart_set.all %} {{ album.albumart.image }} {% endfor %} Is this not supported in list_detail.object_list? I can't find information on this anywhere, may have to change my database around. On Aug 22, 11:44 am, nek4life <[EMAIL PROTECTED]> wrote: > Awesome. I got it to work using this code in my view. > > def artist_detail(request, slug): > album_list = Album.objects.all() > return list_detail.object_detail( > request, > queryset = Artist.objects.all(), > slug = slug, > template_object_name = 'artist', > extra_context={'album_list': album_list} > ) > > But the way you're doing it only calls the database once instead of > twice. Beautiful! Thank you. I'm going to try the query you > suggested. > > queryset=Artist.objects.select_related().all() > > I'd like to just pull in the albums, artwork, and tracks related to > the particular artist in the url slug, for > instancehttp://www.example.com/artists/artist-name > > You've been a huge help. Thanks a ton! > > Charlie > > On Aug 22, 11:20 am, lingrlongr <[EMAIL PROTECTED]> wrote: > > > Also note, if your intentions were to grab all that information and > > just send the artist to the template, I think you'd get better > > performance if your queryset in the view looked like this: > > > queryset=Artist.objects.select_related().all() > > > Keith > > > On Aug 22, 11:17 am, lingrlongr <[EMAIL PROTECTED]> wrote: > > > > Super easy :) Just to show you another way to implement generic > > > views, I used custom view that returns a generic view. > > > > # urls.py > > > from myapp.views import artist > > > ... > > > (r'^artist/(?P\w+)/$', artist), > > > ... > > > > #views.py > > > from django.views.generic.list_detail import object_detail > > > def artist(request, slug): > > > return object_detail( > > > request, > > > queryset=Artist.objects.all(), > > > slug = slug, > > > template_object_name = 'artist' > > > ) > > > > # //artist_list.html > > > {{ artist }} > > > Albums > > > > > > {% for album in artist.album_set.all %} > > > {{ album.name }} > > > > > > {% for track in album.track_set.all %} > > > {{ track.name }} > > > {% endfor %} > > > > > > {% endfor %} > > > > > > > Django makes traversing relationships easy... > > > > HTH > > > > Keith > > > > On Aug 22, 10:03 am, nek4life <[EMAIL PROTECTED]> wrote: > > > > > So if I sent the artist to the template and wanted to grab the list of > > > > albums with all the album tracks how would I go about that. Would I > > > > have to pull in all the data with a custom view? So far I've only > > > > been using generic views. It definitely makes sense pulling in the > > > > information through the track back up through the album to the artist, > > > > how could I reverse the process so I can get all the artist vars plus > > > > the data I need from the track and album tables? Thanks a bunch, > > > > you've been very helpful already. > > > > > Charlie > > > > > On Aug 22, 12:26 am, lingrlongr <[EMAIL PROTECTED]> wrote: > > > > > > One more note. You wouldn't NEED to explicitly grab all those vars, > > > > > as you can get them in a template too. I just wanted to show you the > > > > > relation. > > > > > If you sent the track to the template, you can get the artist by > > > > > using: > > > > > > {{ track.album.artist }} > > > > > > Keith > > > > > > On Aug 22, 12:24 am, lingrlongr <[EMAIL PROTECTED]> wrote: > > > > > > > The only part you have that is redundant is the "artist" in your > > > > > > "Track" class. You can find out the artist because a track is > > > > > > related &g
Re: database relationships
Awesome. I got it to work using this code in my view. def artist_detail(request, slug): album_list = Album.objects.all() return list_detail.object_detail( request, queryset = Artist.objects.all(), slug = slug, template_object_name = 'artist', extra_context={'album_list': album_list} ) But the way you're doing it only calls the database once instead of twice. Beautiful! Thank you. I'm going to try the query you suggested. queryset=Artist.objects.select_related().all() I'd like to just pull in the albums, artwork, and tracks related to the particular artist in the url slug, for instance http://www.example.com/artists/artist-name You've been a huge help. Thanks a ton! Charlie On Aug 22, 11:20 am, lingrlongr <[EMAIL PROTECTED]> wrote: > Also note, if your intentions were to grab all that information and > just send the artist to the template, I think you'd get better > performance if your queryset in the view looked like this: > > queryset=Artist.objects.select_related().all() > > Keith > > On Aug 22, 11:17 am, lingrlongr <[EMAIL PROTECTED]> wrote: > > > Super easy :) Just to show you another way to implement generic > > views, I used custom view that returns a generic view. > > > # urls.py > > from myapp.views import artist > > ... > > (r'^artist/(?P\w+)/$', artist), > > ... > > > #views.py > > from django.views.generic.list_detail import object_detail > > def artist(request, slug): > > return object_detail( > > request, > > queryset=Artist.objects.all(), > > slug = slug, > > template_object_name = 'artist' > > ) > > > # //artist_list.html > > {{ artist }} > > Albums > > > > {% for album in artist.album_set.all %} > > {{ album.name }} > > > > {% for track in album.track_set.all %} > > {{ track.name }} > > {% endfor %} > > > > {% endfor %} > > > > > Django makes traversing relationships easy... > > > HTH > > > Keith > > > On Aug 22, 10:03 am, nek4life <[EMAIL PROTECTED]> wrote: > > > > So if I sent the artist to the template and wanted to grab the list of > > > albums with all the album tracks how would I go about that. Would I > > > have to pull in all the data with a custom view? So far I've only > > > been using generic views. It definitely makes sense pulling in the > > > information through the track back up through the album to the artist, > > > how could I reverse the process so I can get all the artist vars plus > > > the data I need from the track and album tables? Thanks a bunch, > > > you've been very helpful already. > > > > Charlie > > > > On Aug 22, 12:26 am, lingrlongr <[EMAIL PROTECTED]> wrote: > > > > > One more note. You wouldn't NEED to explicitly grab all those vars, > > > > as you can get them in a template too. I just wanted to show you the > > > > relation. > > > > If you sent the track to the template, you can get the artist by > > > > using: > > > > > {{ track.album.artist }} > > > > > Keith > > > > > On Aug 22, 12:24 am, lingrlongr <[EMAIL PROTECTED]> wrote: > > > > > > The only part you have that is redundant is the "artist" in your > > > > > "Track" class. You can find out the artist because a track is related > > > > > to an album, which in turn, is related to an artist. > > > > > > Some of the code you'd maybe see in a view would be: > > > > > > # views.py > > > > > from django.shortcuts import get_object_or_404 > > > > > from models import Album, Track > > > > > > def album(request, slug): > > > > > album = get_object_or_404(Album, slug=slug) > > > > > artist = album.artist > > > > > tracks = album.track_set.all() > > > > > ...etc... return a response... > > > > > > def track(request, slug): > > > > > track = get_object_or_404(Track, slug=slug) > > > > > album = track.album > > > > > artist = album.artist > > > > > ..etc.. > > > > > > HTH > > > > > > Keith > > > > > > On Aug 21, 11:44 pm, nek4life <[EMAIL PROTECTED]> wrote: > > > > > > > I'm trying to set up my first Django application and I
Re: database relationships
So if I sent the artist to the template and wanted to grab the list of albums with all the album tracks how would I go about that. Would I have to pull in all the data with a custom view? So far I've only been using generic views. It definitely makes sense pulling in the information through the track back up through the album to the artist, how could I reverse the process so I can get all the artist vars plus the data I need from the track and album tables? Thanks a bunch, you've been very helpful already. Charlie On Aug 22, 12:26 am, lingrlongr <[EMAIL PROTECTED]> wrote: > One more note. You wouldn't NEED to explicitly grab all those vars, > as you can get them in a template too. I just wanted to show you the > relation. > If you sent the track to the template, you can get the artist by > using: > > {{ track.album.artist }} > > Keith > > On Aug 22, 12:24 am, lingrlongr <[EMAIL PROTECTED]> wrote: > > > The only part you have that is redundant is the "artist" in your > > "Track" class. You can find out the artist because a track is related > > to an album, which in turn, is related to an artist. > > > Some of the code you'd maybe see in a view would be: > > > # views.py > > from django.shortcuts import get_object_or_404 > > from models import Album, Track > > > def album(request, slug): > > album = get_object_or_404(Album, slug=slug) > > artist = album.artist > > tracks = album.track_set.all() > > ...etc... return a response... > > > def track(request, slug): > > track = get_object_or_404(Track, slug=slug) > > album = track.album > > artist = album.artist > > ..etc.. > > > HTH > > > Keith > > > On Aug 21, 11:44 pm, nek4life <[EMAIL PROTECTED]> wrote: > > > > I'm trying to set up my first Django application and I'm trying to > > > figure out the database relationships. I want to be able to list > > > albums, with their corresponding tracks and album artwork. Right now > > > I only have foreign keys defined in the Track class and on the > > > AlbumArt class pointing to the Album class. I'm doing this so I can > > > keep a record of which track or which album art goes to which album. > > > However I also would like to add a ManyToManyField on my Album class > > > so I can pull the album data in my view. Defining this is both places > > > seems redundant to me, but I'm not sure how else I can accomplish > > > this. What would be best practice in this situation and how should I > > > proceed? > > > > class Album(models.Model): > > > title = models.CharField(max_length=255) > > > prefix = models.CharField(max_length=20, blank=True) > > > subtitle = models.CharField(blank=True, max_length=255) > > > slug = models.SlugField(unique=True) > > > artist = models.ForeignKey('Artist') > > > > class AlbumArt(models.Model): > > > title = models.CharField(max_length=200) > > > slug = models.SlugField() > > > album = models.ForeignKey('Album') > > > > class Track(models.Model): > > > title = models.CharField(max_length=200) > > > slug = models.SlugField(unique=True) > > > album = models.ForeignKey('Album') > > > artist = models.ForeignKey('Artist') --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
database relationships
I'm trying to set up my first Django application and I'm trying to figure out the database relationships. I want to be able to list albums, with their corresponding tracks and album artwork. Right now I only have foreign keys defined in the Track class and on the AlbumArt class pointing to the Album class. I'm doing this so I can keep a record of which track or which album art goes to which album. However I also would like to add a ManyToManyField on my Album class so I can pull the album data in my view. Defining this is both places seems redundant to me, but I'm not sure how else I can accomplish this. What would be best practice in this situation and how should I proceed? class Album(models.Model): title = models.CharField(max_length=255) prefix = models.CharField(max_length=20, blank=True) subtitle = models.CharField(blank=True, max_length=255) slug = models.SlugField(unique=True) artist = models.ForeignKey('Artist') class AlbumArt(models.Model): title = models.CharField(max_length=200) slug = models.SlugField() album = models.ForeignKey('Album') class Track(models.Model): title = models.CharField(max_length=200) slug = models.SlugField(unique=True) album = models.ForeignKey('Album') artist= models.ForeignKey('Artist') --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Unexpected Keyword Argument 'radio_admin'
I'm getting the same error, and I can't see when the manger isn't being imported... 'Manager' object has no attribute 'published' This is driving me crazy. Any Ideas, I had it working with Django 96.2 but not beta 1 version I'm running now. On Jun 26, 5:24 pm, Alfonso <[EMAIL PROTECTED]> wrote: > Thanks Karen and Brian for your suggestions. Turned out a combination > of the two (got to read those error messages more closely - cough) > > It was incorrect radio_admin syntax in the 'pluggable' basic blog app > -http://code.google.com/p/django-basic-apps/, had to clear pyc's as > well. > > Now got a new error now - > > AttributeError at / > 'Manager'objecthasnoattribute'published' > > Which is linked to the basic-blog app. Strange because code was > working fine prior to newforms issue. > > I look forward to the day when I can confidently produe error free > django apps! > > Thanks > > Allan > > On Jun 26, 8:38 pm, Brian Rosner <[EMAIL PROTECTED]> wrote: > > > On Jun 26, 2008, at 10:09 AM, Alfonso wrote: > > > > TypeError: __init__() got an unexpected keyword argument > > > 'radio_admin'. > > > > Where did that come from? > > > Sounds like you may have some lingering .pyc files that might be > > causing this from newforms-admin if you have switched your copy of > > Django from newforms-admin to trunk.\ > > > Brian Rosnerhttp://oebfare.com --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---