deleted_forms and invalid formset
Hi, Please take a look at https://github.com/django/django/blob/master/django/forms/formsets.py#L204 if not self.is_valid() or not self.can_delete: Anyone can give me rationale behind condition with is_valid? Shouldn't deleted_forms be available also in case when formset is invalid? Regards, Bartek -- 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/0b66eb3f-6feb-42ba-bb0c-9829d23c13e7%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Banners managment
On Wed, 20 Apr 2011 22:52:39 -0300 Alex s <alexsalga...@gmail.com> wrote: > Hi people > > Have anyone some experience to explain about use a django app for > Banners managment ? > > Thanks > Alex > I use this: https://bitbucket.org/bartekgorny/djbanner Bartek -- "Jeśli boli cię gardło, ciesz się że nie jesteś żyrafą (zauważone w aptece) -- 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.
Re: strange behaviour of custom view based on date_based.object_detail - random 404
Bartek SQ9MEV pisze: [...] > Enviroment: > python-2.6.1 > python-apache-2.2.11 > psycopg2-2.0.11 > apache-mod_wsgi-2.5 > glibc-2.10.1 [...] Update: apache-2.2.11 mpm prefork -- B --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
strange behaviour of custom view based on date_based.object_detail - random 404
I've got some strange problems in my hosting enviroment using mod_wsgi like that: WSGIDaemonProcess mygroup user=myuser group=users processes=3 threads=10 display-name=mygroup Enviroment: python-2.6.1 python-apache-2.2.11 psycopg2-2.0.11 apache-mod_wsgi-2.5 glibc-2.10.1 The problem is that random requests (originating from the same client which is ab -n 1000 -c 3 http://...) generates 404, because these requests generates different sql: Query which is OK as I think: SELECT "pressroom_article"."id", "pressroom_article"."pub_date", "pressroom_article"."headline", "pressroom_article"."slug", "pressroom_article"."summary", "pressroom_article"."body", "pressroom_article"."author_id", "pressroom_article"."publish", "pressroom_article"."enable_comments" FROM "pressroom_article" WHERE ("pressroom_article"."pub_date" <= E'2009-09-29 13:54:00.806995' AND "pressroom_article"."publish" = true AND "pressroom_article"."pub_date" BETWEEN E'2009-09-29 00:00:00' and E'2009-09-29 23:59:59.99' AND "pressroom_article"."slug" = E'spotting-na-jfk' AND "pressroom_article"."pub_date" <= E'2009-09-29 13:54:00.808648' ) ORDER BY "pressroom_article"."pub_date" DESC ^^^ And the one which renders 404 is WHERE ("pressroom_article"."pub_date" <= E'2009-09-29 06:55:06.859015' AND "pressroom_article"."publish" = true AND The question is - what's wrong? it happens in different projects. My setting: TIME_ZONE = 'Europe/Warsaw' My Model is (it's modified part of http://code.google.com/p/django-pressroom/): class ArticleManager(models.Manager): def get_published(self): return self.filter(publish=True, pub_date__lte=datetime.now) def get_drafts(self): return self.filter(publish=False) class Article(models.Model): pub_date = models.DateTimeField("Publish date", default=datetime.now) headline = models.CharField(max_length=200) slug = models.SlugField(help_text='A "Slug" is a unique URL-friendly title for an object.') summary = models.TextField(help_text="A single paragraph summary or preview of the article.") body = models.TextField("Body text") #author = models.CharField(max_length=100) author = models.ForeignKey(User, verbose_name="Author" ) publish = models.BooleanField("Publish on site", default=True, help_text='Articles will not appear on the site until their "publish date".') sections = models.ManyToManyField('Section', related_name='articles') photos = models.ManyToManyField(Photo, related_name='articles', null=True, blank=True) documents = models.ManyToManyField('Document', related_name='articles', null=True, blank=True) enable_comments = models.BooleanField(default=True) # Custom article manager objects = ArticleManager() [...] And my view is: def article_detail(request, *args, **kwargs): kwargs['queryset'] = Article.objects.get_published() return date_based.object_detail(request, *args, **kwargs) Another view in another project which act the same is: def my_akt_detail(request, *args, **kwargs): kwargs['queryset'] = Akt.objects.select_related('zrodla').filter(visible_since__lte=datetime.now()) return date_based.object_detail(request, *args, **kwargs) In above views I use intentionally my own views to get rid of cache-like queryset behaviour like http://pascut.com/2008/08/16/django-generic-views-cache-behavior/ It does not matter, if in my view i return Article.objects.get_published() or Article.objects.all() - It's probably because default value of allow_future=False in date_based.object_detail Strange thing is that 404 NOT FOUND appears random, sometimes it's 25%, 30, or even about 70% times. For now i'm not sure, if original date_based.object_detail is buggy in my enviroment. Any ideas? -- B. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
inlineformset_factory causing some KeyError whackiness.
Hi, I am trying to use the inlineformset_factory on an odd model I have created. Here's the best way I can describe it: class Base(models.Model): title = models.CharField(max_length=55) def save(self, *args, **kwargs): if self.is_editable(): # do a bunch of things self.pk = None super(Base, self).save(*args, **kwargs) class Inline(models.Model): base = models.ForeignKey(Base) Basically, Base will always create an entirely new instance of itself, unless the is_editable returns false. This is basically a cheap way of having a true "version history" of the entire model. It works, until we get to my foreign key relation. In my view, I have a simple: InlineFormset = inlineformset_factory(Base, Inline, extra=0, fields ('id', 'body',)) if request.method == 'POST': new_base = form_base.save() # a simple modelform, this is. inline_formset = InlineFormset(request.POST, instance=new_base) if inline_formset.is_valid(): inline_formset.save() As soon as I hit the save(), I get a KeyError: None Traceback shows it's happening within the core saving function within django's model.py: /home/bartek/.virtualenvs/tinyescrow/lib/python2.6/site-packages/ django/forms/models.py in save_existing_objects # Put the objects from self.get_queryset into a dict so they are easy to lookup by pk existing_objects = {} for obj in self.get_queryset(): existing_objects[obj.pk] = obj saved_instances = [] for form in self.initial_forms: print form.cleaned_data, self._pk_field.name obj = existing_objects[form.cleaned_data [self._pk_field.name]] ... if self.can_delete and form.cleaned_data [DELETION_FIELD_NAME]: self.deleted_objects.append(obj) obj.delete() else: if form.changed_data: self.changed_objects.append((obj, form.changed_data)) So basically, I'm not sure why I would get this KeyError. I am certain it has something to do with what I'm doing with the Base models primary key but I am not sure how to get around it. I've used inlineformset_factory successfully on normal models without weird pk's so it's a great function, just need to figure this out :) Thanks in advance for any 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django and Ajax (mootools/clientcide) Fupdate encoding problems
Karen Tracey pisze: > > Sharing with the list what, exactly, the 'results far from expected' > look like would be a start. I assume from the subject that you are > getting some sort of encoding exception, but without the traceback it is > a bit difficult to say where exactly the problem is. Indeed, i'd have been more precise... "far from expected" means, that characters "śś" are saved as "ść ść" There's no encoding exception, so i think that the reason is bad encodnig by Fupdate, or just Django can't handle proper encoding of correct data supplied by Fupdate. I've found out that clientcide Fupdate makes some "magic" with form data, so I've changed a little code of clientcide Fupdate (http://groups.google.com/group/clientside/browse_frm/thread/e72931ed9260369d), and it works well now, I don't know if this problem is more server or client side specyfic... -- Bartek --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Django and Ajax (mootools/clientcide) Fupdate encoding problems
Hi Im using clientcide fupdate which generates ajax request: http://dpaste.com/38671/ My post data includes some national (polish) characters, when i try to save them i get results far from expected. My view is at http://dpaste.com/38672/ What would be the best idea to handle this problem? Where does it originate? Any idea where to start investigation? -- Bartek --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
date_list in date_based.archive_index and date_based.archive_year but why not in archive_list and archve_month?
Hi Why there are not extra_centext date_list in date_based views except archive_index and archive_year? I've found this: http://code.djangoproject.com/ticket/3274 but this patch isn't applied in Django-1.0.2-final.tar.gz? What is the best way to have date_list in archive_list and archive_month except modifying Django generic views code? Is the the custom template tag with passed queryset as variable the only way? -- Bartek --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: pagination
Konstantin S pisze: > Hello! > second one I found at code.google.com. (Url is > http://code.google.com/p/django-pagination/). Which one would you > recommend ? This one works well for me (it uses the built-one), but remember not to use {% if object_list %} before pagination tags in your template - the "if" tag evaluates the queryset, that was cause of big overhead in one of my apps.. Discussion few months ago: http://www.tinyurl.pl?Q4IaEv3v -- jid: b.rad...@chrome.pl --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: django 1.0.2, django_pagination-1.0.5, postgresql, LIMIT & OFFSET question
Karen Tracey pisze: > On Wed, Feb 4, 2009 at 3:01 AM, Bartek SQ9MEV <bar...@sq9mev.info > <mailto:bar...@sq9mev.info>> wrote: [...] > So, any idea where's the clue? > Is it possible to use django-pagination with generic views without so > senseless overhead? > The cause was the {% if posts_list %} tag, which evaluates the queryset before the limit was applied. Now it's obvious for me ;). Django-pagination works well. -- Bartek --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: django 1.0.2, django_pagination-1.0.5, postgresql, LIMIT & OFFSET question
Bartek pisze: > so... looks like everytime I need 20 Post items my database is hit by > query returning all records... I find it a big overhead, and my app > suffers from that... Today I'm still investigating this issue, and I've just tried to use Paginator object as described at http://docs.djangoproject.com/en/dev/topics/pagination/#topics-pagination with my Post model described ina my previous post. Funny thing is that it's OK - sql for any page is: SELECT "galgather_post"."id", "galgather_post"."group_id", "galgather_post"."messageid", "galgather_post"."subject", "galgather_post"."author_id", "galgather_post"."posting_date", "galgather_post"."date_added" FROM "galgather_post" ORDER BY "galgather_post"."posting_date" DESC LIMIT 10 OFFSET 10 triggered by: posts=Post.objects.all() p=Paginator(posts,10) page2=p.page(2) page2.object_list So, any idea where's the clue? Is it possible to use django-pagination with generic views without so senseless overhead? -- Bartek --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
django 1.0.2, django_pagination-1.0.5, postgresql, LIMIT & OFFSET question
Hi all Using django-pagination, I encounter some serious performance problems related to django-pagination. Request for every page triggers sql query returning all Post instances, here's detailed description of my problem: My model Is: class Post(models.Model): group = models.ForeignKey(Group, verbose_name='Grupa',) messageid = models.CharField("Message-Id", max_length=512) subject = models.CharField("Subject", max_length=512) author = models.ForeignKey(Author, verbose_name="Autor") posting_date= models.DateTimeField("NNTP-Posting-Date", blank=True) date_added = models.DateTimeField("Dodany", auto_now_add=True) def __unicode__(self): return "[%s] %s" % (self.group, self.messageid) class Meta: ordering=['-posting_date'] and urls: posts_dict={ 'queryset': Post.objects.all(), 'template_name': 'galgather/posts_archive.html', 'allow_empty':True, 'template_object_name':'posts', } [...] url(r'/$', object_list, dict(posts_dict), 'posts_archive',), [...] I want to paginate over Posts.objects.all(), so in my template i use: {% autopaginate posts_list 20 %} {% paginate %} {% for post in posts_list %} [...] {% endfor %} The problem is that every request for each page generates sql queries fetching all objects, than django asks about Post count. Queries looks like that: SELECT "galgather_post"."id", "galgather_post"."group_id", "galgather_post"."messageid", "galgather_post"."subject", "galgather_post"."author_id", "galgather_post"."posting_date", "galgather_post"."date_added" FROM "galgather_post" ORDER BY "galgather_post"."posting_date" DESC SELECT COUNT(*) FROM "galgather_post" >>> Post.objects.count() 18145L so... looks like everytime I need 20 Post items my database is hit by query returning all records... I find it a big overhead, and my app suffers from that... I've read: http://code.google.com/p/django-pagination/issues/detail?id=15 and http://code.google.com/p/django-pagination/source/detail?r=27 and wandering if its normal behaviour? If not, what could the cause of that nasty problem? My python knowledge however still improoving, but still isn't sufficient to quick analyze django code. Thanks in advance -- Bartek spamtrap: http://sq9mev.info/spamtrap.html --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: custom templatetags and problem with importing photologue.models - namespace collision?
Bartek pisze: > Hi all > When I loop over sys.modules in templatetags/pobierz.py there's > django.templatetags.photologue, so probably that's why "from > photologue.models import Gallery" throws ImportException - there's not > models in django.templatetags.photologue > > Anyway in sys.modules there's photologue.models as well. > Is there any way to import models from photologue? I found solution myself today which is: localphotologue=sys.modules['photologue.models'] gals=localphotologue.Gallery.objects.all().order_by('?')[:4] Is this the correct, pythonic way? -- Bartosz Radwan jid: bar...@sq9mev.info spamtrap: http://sq9mev.info/spamtrap.html --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
custom templatetags and problem with importing photologue.models - namespace collision?
Hi all I've experienced problems with import photologue.models into my templatetag module. When I loop over sys.modules in templatetags/pobierz.py there's django.templatetags.photologue, so probably that's why "from photologue.models import Gallery" throws ImportException - there's not models in django.templatetags.photologue Anyway in sys.modules there's photologue.models as well. Is there any way to import models from photologue? It seems solution is easy, but I spent some time on it and got confused... All I want to do is inclusion tag that renders some objects from my models in flatpages... I've done it with my own models, the only problem is photologue. Thanks in advance. -- Bartosz Radwan jid: bar...@sq9mev.info spamtrap: http://sq9mev.info/spamtrap.html --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
How to delete template fragment cache?
Hi all, I'm quite newbie in Django. I use template fragment caching ({% cache ...%}...{% endcache %}. This fragment changes rather seldom, changes originate only from admin site, są for me its obvious to delete cache at adding objects from admin, and use quite large tiemeout for my caches. How can I delete cache for particular fragments at saving objects? I know I should use cache.delete('a'), but how can I get key for particular fragment? What is better idea? Use signals (I do not know too mouch about them yet)or just overwrite model_save method? I use memcached backend. -- Pozdrawiam Bartek jid: [EMAIL PROTECTED] --~--~-~--~~~---~--~~ 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: How do I install Django in Windows Vista?
Extract it, run setup.py and turn on the dev server or configure to work with apache and you're good to go.. Pretty much like you would on any OS, just different paths and "rules" sometimes On Wed, Jun 18, 2008 at 9:46 PM, redxblade717 <[EMAIL PROTECTED]> wrote: > > I'm running Vista. I have Python 2.5 installed. I tried the method in > which all you do is extract the official version of Django into C: > \Python25\Lib\site-packages folder. So far I have yet to actually use > django. What do I do? I wanna start learning and developing but > installing this is near impossible. > > > > --~--~-~--~~~---~--~~ 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: Media variables confusion
You need MEDIA_ROOT because yes, you serve it from static.serve view during development but when you launch you do not want to be using the devserver to display your site. MEDIA_URL is essentially the same url you map through Apache, lighthttpd, whatever you use But you are right, you can use the dev server to setup where your media is but once you go onto a more public launch viewing you will want to switch using Apache / mod_python combo or something else. This describes it pretty well: http://www.djangoproject.com/documentation/modpython/#serving-media-files On Tue, Jun 17, 2008 at 3:27 PM, Alaa Salman <[EMAIL PROTECTED]> wrote: > Hey guys, > > So i am a little confused by the MEDIA_ROOT, MEDIA_URL, and > ADMIN_MEDIA_PREFIX variables. > > I understand that the ADMIN_MEDIA_PREFIX provides the prefix. But so what > if it was on another url? I am assuming that the common use case is to serve > them from the same domain, which is what i am doing. But just in case... > > Also, why do we need a MEDIA_ROOT as a path to a directory if we can use > the static.serve view during development? And then so why are both the > MEDIA_URL and MEDIA_ROOT needed? > > As you can see, I'm a little confused by these settings and have managed to > develop with using them this far. So any explanation is appreciated. I find > the documentation a little lacking in explaining these vars. > > > Regards, > Alaa Salman > http://www.codedemigod.com > FSF Member #6304 > "Never measure the height of a mountain until you have reached the top. > Then you will see how low it was." ---Dag Hammarskjold > > > --~--~-~--~~~---~--~~ 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: Filter based on empty date field
You could use the isnull filter: http://www.djangoproject.com/documentation/db-api/#isnull If your model is setup correctly, that'll do the trick On Sat, Jun 14, 2008 at 2:03 PM, robbie <[EMAIL PROTECTED]> wrote: > > Hi! > > I'd like to know if there is any way you can filter a data-set based > on an empty DateTimeField? Let's say I have a Message model with a > DateTimeField named read; what I would like to do is to list all > messages with an empty (null) read field. > This is probably very easy, but I'm new to both Python and Django, so > don't be too hard on me. :) > > > > --~--~-~--~~~---~--~~ 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: Filtering a query based on potential arguments
Thanks Tim for the code optimization ideas. Very pythonic of you ;) On Sat, Jun 14, 2008 at 10:55 AM, Tim Chase <[EMAIL PROTECTED]> wrote: > > >> cards = Card.objects.all() > >> if request.POST.get('brand') : > >> cards = cards.filter(brand = request.POST.get('brand')) > >> if request.POST.get('year') : > >> cards = cards.filter(year = request.POST.get('year')) > > > > Scott: Very cool, didn't know that was possible. I'm sure this > > does not hurt > > This can even be dumped in a loop, using dictionary kwargs which > makes it more DRY: > > cards = Card.objects.all() > for field in ('brand', 'year', 'color', 'size'): > if field in request.POST: > cards = cards.filter(**{ > field: request.POST.get(field) > }) > > This separates out the common code, and reduces the field-names > to just being entries in a list for which the same action is > performed for each. > > Given that they're ANDed together, you might even be able to just > build the dictionary, and then unpack that as your filter: > > fieldnames = ('brand', 'year', 'color', 'size') > kwargs = dict( > (field, request.POST.get(field)) > for field in fieldnames > if field in request.POST > ) > cards = Card.objects.filter(**kwargs) > > This *could* be reduced to a single (much more opaque) statement, > but I usually prefer to keep a little readability compared to > > cards = Card.objects.filter(**dict( > (field, request.POST.get(field)) > for field in ('brand', 'year', 'color', 'size') > if field in request.POST > )) > > I haven't delved into the new QS-RF code to see whether the > resulting queries differ vastly in meaning/efficiency, but I > remember there being a subtle difference between chained filters > vs. multiple filters applied at the same time (though that may > have only applied to related models). > > -tim > > > > > > > --~--~-~--~~~---~--~~ 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: Filtering a query based on potential arguments
Scott: Very cool, didn't know that was possible. I'm sure this does not hurt performance much compared to the other method shown above? Needless to say it works great! Thanks much On Thu, Jun 12, 2008 at 5:58 AM, Scott Moonen <[EMAIL PROTECTED]> wrote: > You can take advantage of the fact that query sets are not executed until > they are inspected: > > cards = Card.objects.all() > if request.POST.get('brand') : > cards = cards.filter(brand = request.POST.get('brand')) > if request.POST.get('year') : > cards = cards.filter(year = request.POST.get('year')) > . . . > > -- Scott > > On Thu, Jun 12, 2008 at 5:42 AM, caustic <[EMAIL PROTECTED]> wrote: > >> >> >> >> On Jun 12, 10:55 am, truebosko <[EMAIL PROTECTED]> wrote: >> > I have a card store and I would like to add 3 options a user can >> > search by. Year, Brand, and Card Title >> > >> > Normally this would be easy but my dilemna here is: >> > - All of these are optional, and if they do not search for a certain >> > one, the query should ignore that filter entirely and display in full >> > (So if none of the filters are active I display ALL cards) >> > >> > So basically what I am thinking of was: >> > >> > if request.POST.get('brand'): >> > Q(brand=request.POST.get('brand') >> > >> > if request.POST.get('year'): >> > Q(year=request.POST.get('year') >> > >> > etc. >> > >> > cards = Card.objects.filter(... Now how do I get those Q objects into >> > here ??).order_by('pk') >> >> Try >> cards = Card.objects.filter(Q1) >> >> Alternatively you can use a dictionary and ** magic: >> filter = dict(brand=request.POST.get('brand'), >> year=request.POST.get('year')) >> cards = Card.objects.filter(**filter) >> >> > > > -- > http://scott.andstuff.org/ | http://truthadorned.org/ > > > > --~--~-~--~~~---~--~~ 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: Form Validation for GET Request
Maybe because you actually have to pass `action`? ;) Pass it through your form. Maybe my use of 'action' confused you with the 's action property. Not what I meant, sorry. I didn't realize you had an actual form (Wait, why do you .. Ok, beyond the point) but in this case you can just check for any value within your form and see if it's True If your form has a "name" field you could do: if request.GET.get('name'): ... Your initial problem is when you load a page, that Is a GET request so that's why it was going through. On Fri, Jun 13, 2008 at 10:45 PM, ichbindev <[EMAIL PROTECTED]> wrote: > > This is what my template looks like: > > {{ form.as_table }} table> > > This is what my view looks like: > > ... > myform = MyForm() > if request.method=="GET": >myform = MyForm(request.GET) > if request.GET.get('action') == True: > if myform.is_valid(): >... > ... > return render_to_response ('template.html', {'form' : myform}) > > When I first go to the page, requet.GET.get('action') is None. When I > click the 'submit' button, again requet.GET.get('action') is None. I > used HttpResponse to return requet.GET.get('action') as a string. > > > --~--~-~--~~~---~--~~ 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: Form Validation for GET Request
If errors are showing when you first load the page then you need to check that the user has actually completed an action before validating the form. In this case, doing something like if request.GET.get('action') == True: # your form validation here In your links back to the system, simply add an ?action=true (or whatever) and that'll fix your issue there. On Fri, Jun 13, 2008 at 10:03 PM, ichbindev <[EMAIL PROTECTED]> wrote: > > The problem is when I use > > myform = MyForm(request.GET) > if myform.is_valid(): > ... > > Any fields which are required have their error message activated on > first visit to page. Also, any 'initial' value that I put in the forms > is not shown. > > > > --~--~-~--~~~---~--~~ 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: DB Models best practice
Instead of over complicating it like this. Why not just use memcached or django's own cache? On Thu, Jun 12, 2008 at 11:45 AM, Juan Hernandez <[EMAIL PROTECTED]> wrote: > Hey there, I have a question concerning performance and best practices > > I have this piece of code in one of my views > > = > # query execution > def db(): > return bp.objects.all() > > def title(): > x = db() > y = x[0].title > return y > > def blogSubtitle(): > return bp.objects.all()[0].blogSubtitle > = > > What I'm trying to do is: Having my methods go to the DB only once and then > getting everything from memory but I don't think I'm accomplishing that. I > get all the records in the query() method and then, title for example, uses > it and gets what it want and the blogSubtitle() goes directly and makes > another query . My question is: if I use the title() method, everytime I > call the query() method, it would be executing another query right? just as > if I was executing that query inside the method. I've seen many examples in > the documentation and I haven't been able to figure the best way to do it. I > just want to execute a big query once and then, get everything from memory > without going back to the db. > > Thanx > jhv > > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---