Re: Any good books for learning django?
Ah, PyDanny and Audrey's Two Scoops is a great primer once you've done the excellent tutorial that is on the Django site https://django.2scoops.org/ I'm a very happy owner. L. On 27 July 2013 12:43, Yinkawrote: > Is there any hope that we'll ever get an up-to-date book for learning > Django? > > Rails 4 was released only last month and I can count at least 4 books (at > various stages of completion) on sale to guide beginners. > > I love Django and but it's been difficult having to depend ONLY on the > documentation to learn, don't get me wrong - the docs tutorial is good but > is just not the right 'book' for beginners. > > Thank you. > > > On Thursday, February 7, 2013 5:49:36 PM UTC, frocco wrote: >> >> Hello, >> Most of what I find are dated, 2008,2009. >> Are these still good for learning django 1.4? >> >> Which books do you recommend? >> >> Thanks > > -- > 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. > For more options, visit https://groups.google.com/groups/opt_out. > > -- We are like a drunk blundering through a crowd of pickpockets. That we are not poor and naked already is a testament to either the goodness of humanity or the ineptitude of the criminal class. http://techcrunch.com/2013/06/08/we-asked-for-this/ -- 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. For more options, visit https://groups.google.com/groups/opt_out.
Re: Any good books for learning django?
Is there any hope that we'll ever get an up-to-date book for learning Django? Rails 4 was released only last month and I can count at least 4 books (at various stages of completion) on sale to guide beginners. I love Django and but it's been difficult having to depend ONLY on the documentation to learn, don't get me wrong - the docs tutorial is good but is just not the right 'book' for beginners. Thank you. On Thursday, February 7, 2013 5:49:36 PM UTC, frocco wrote: > > Hello, > Most of what I find are dated, 2008,2009. > Are these still good for learning django 1.4? > > Which books do you recommend? > > Thanks > -- 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. For more options, visit https://groups.google.com/groups/opt_out.
Changing log filename
I have a standard logger that I would like to use for all of my applications, the only thing I want to change is the name of the file. Is there a way to do that with out having to create a logger and handler for each of my apps. Here is the logging settings that I am using. LOGGING = { 'version': 1, 'disable_existing_loggers': True, 'formatters': { 'standard': { 'format' : "[%(asctime)s] %(levelname)s [%(module)s:%(lineno)s] %(message)s", 'datefmt' : "%d/%b/%Y %H:%M:%S" }, }, 'handlers': { 'app_logger': { 'level':'DEBUG', 'class':'logging.handlers.TimedRotatingFileHandler', 'filename': '/var/log/django/app.log', 'backupCount': 5, 'when' : 'midnight', 'formatter': 'standard', }, }, 'loggers': { 'myproject': { 'handlers': ['app_logger'], 'level': 'INFO', } } } In my app I would like to be able to override the 'filename': '/var/log/django/another_app.log', import logging log = logging.getLogger('myproject') log.info("Something here") Any ideas? -- 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. For more options, visit https://groups.google.com/groups/opt_out.
Re: Advanced Tutorial (how to write reusable app), last step does not work
On 27/07/2013 10:20am, Cate Liu wrote: I am a new newbie to Django. Great tutorial BTW. I followed it to the T and 99.9% worked. Except the last step in the Advanced tutorial, the step 3 in 'Using your own package'. I could see http://127.0.0.1:8000/admin/ and create polls without any problem. But http://127.0.0.1:8000/polls/ would give me the following error. I see there are two problems. 1. |/Users/nnn/django_exercises/mysite/templates/polls/index.html is the wrong location, it should be $$/django_polls/polls/templates/polls/index.html. 2. What is ||polls/poll_list.html?| Nowhere in the tutorial ever created this file, no? I don't know the tutorial and haven't looked through it but you have definitely called for poll_list.html somewhere in your code. The first place to look is in your urls.py. Try and see how the URL you entered is being interpreted. It is probably calling a view (in views.py?) which names poll_list.html directly. I put print statements in my settings.py if DEBUG == True which show my static, media and template locations every time I use manage.py runserver. It is very helpful when debugging file locations. You might also try http://127.0.0.1:8000/admin/polls/ Thanks for any advice. -- TemplateDoesNotExist at /polls/ polls/index.html, polls/poll_list.html Request Method: GET Request URL:http://127.0.0.1:8000/polls/ Django Version: 1.5.1 Exception Type: TemplateDoesNotExist Exception Value: polls/index.html, polls/poll_list.html Exception Location: /Library/Python/2.7/site-packages/django/template/loader.py in select_template, line 194 Python Executable: /usr/bin/python Python Version: 2.7.2 Python Path: ['/Users/nnn/django_exercises/mysite', '/Users/nnn/py_pkg/lib/python/django_polls-0.1-py2.7.egg', '/Users/nnn/py_pkg/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', '/Library/Python/2.7/site-packages'] Server time:Fri, 26 Jul 2013 16:59:14 -0700 Template-loader postmortem Django tried loading these templates, in this order: * Using loader |django.template.loaders.filesystem.Loader|: o |/Users/nnn/django_exercises/mysite/templates/polls/index.html, polls/poll_list.html| (File does not exist) * Using loader |django.template.loaders.app_directories.Loader|: o |/Library/Python/2.7/site-packages/django/contrib/auth/templates/polls/index.html, polls/poll_list.html| (File does not exist) o |/Library/Python/2.7/site-packages/django/contrib/admin/templates/polls/index.html, polls/poll_list.html| (File does not exist) -- 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. For more options, visit https://groups.google.com/groups/opt_out. -- 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. For more options, visit https://groups.google.com/groups/opt_out.
Re: Django 1.5 Feature Suggestion
On Fri, Jul 26, 2013 at 10:43 PM, JJ Zolperwrote: > Hello everyone, > > So I want to say thanks to the Django guys for providing more support for > those of us that want to use a user's email as the UID and login handler > versus the previous method of handling based on the username. I and > probably many others appreciate the effort given to the topic and that it > was integrated into Django 1.5. > > Today I would like to request a continuing expansion about this concept. > > In referencing this link: > > > https://geekwentfreak-raviteja.rhcloud.com/2012/12/custom-user-models-in-django-1-5/ > > I would like to request that if we want to make email the UID we don't > have to do things such as: > > class MyUser(AbstractBaseUser, PermissionsMixin): > > is_staff = models.BooleanField('staff status', default=False, > help_text='Designates whether the user can log into this admin ' > 'site.') > is_active = models.BooleanField('active', default=True, > help_text='Designates whether this user should be treated as ' > 'active. Unselect this instead of deleting accounts.') > > def get_full_name(self): > full_name = '%s %s' % (self.first_name, self.last_name) > return full_name.strip() > > def get_short_name(self): > return self.first_name > > just to retain what could already be apart of Django. You guys know more > about Django then I ever will and what the best way is to go about it but > if we can eliminate additional code that is already in Django that would be > wonderful. > > Now in referencing: > > > http://stackoverflow.com/questions/16638414/set-email-as-username-in-django-1-5 > > Basically what I'm saying is, we shouldn't have to do what this fellow had > to do: > > Unfortunately there's nothing within django.contrib.auth that you can > simply subclass to get a model that has > >1. > >email address in place of user name and >2. > >works nicely with other django.contrib.auth-stuff, like groups. > > The simplest approach is to copy models.py, admin.py and forms.py from > django.contrib.auth, rip out user name all over the place and put in > email address in it's place. I've done just that and I'm using it > successfully in a couple of client projects. > > I've put it up on github and pypi so you can install it with > > pip install django-libtech-emailuser > > > I thank you for your time and I appreciate your consideration for > integrating this once and for all into Django. > Hi JJ, That's a fair comment -- "Email address as username" is a sufficiently common use case that it probably warrants being included in Django's core. I think I've overheard Jacob endorsing the same thing at some point in the past (although I'll stand corrected on this if I misheard/misunderstood/misattributed his comments). If you've already done the heavy lifting here, then all we need to do is massage your external package into contrib. Open a ticket and we can see what we can do about getting this in for 1.7. Yours, Russ Magee %-) -- 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. For more options, visit https://groups.google.com/groups/opt_out.
Re: error
On 27/07/2013 5:10am, veda av wrote: manage.py not recognized as an internal or external command why do we get this error manage.py isn't there. Or if it is there it isn't on the path. Did you cut any corners during installation? -- 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. For more options, visit https://groups.google.com/groups/opt_out. -- 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. For more options, visit https://groups.google.com/groups/opt_out.
Re: Django documentation code ?
On 27/07/2013 3:37am, Vinod Halaharvi wrote: Is there a way to download just the code examples listed in the Django documentation pages ? That's not necessarily a good idea but it depends what you want to do.. Why do you want to do that? It wouldn't be too difficult to write a little screen scraper using requests http://docs.python-requests.org/en/latest/ VH -- 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. For more options, visit https://groups.google.com/groups/opt_out. -- 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. For more options, visit https://groups.google.com/groups/opt_out.
error
manage.py not recognized as an internal or external command why do we get this error -- 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. For more options, visit https://groups.google.com/groups/opt_out.
Advanced Tutorial (how to write reusable app), last step does not work
I am a new newbie to Django. Great tutorial BTW. I followed it to the T and 99.9% worked. Except the last step in the Advanced tutorial, the step 3 in 'Using your own package'. I could see http://127.0.0.1:8000/admin/ and create polls without any problem. But http://127.0.0.1:8000/polls/ would give me the following error. I see there are two problems. 1. /Users/nnn/django_exercises/mysite/templates/polls/index.html is the wrong location, it should be $$/django_polls/polls/templates/polls/index.html. 2. What is polls/poll_list.html? Nowhere in the tutorial ever created this file, no? Thanks for any advice. -- TemplateDoesNotExist at /polls/ polls/index.html, polls/poll_list.html Request Method: GET Request URL: http://127.0.0.1:8000/polls/ Django Version: 1.5.1 Exception Type: TemplateDoesNotExist Exception Value: polls/index.html, polls/poll_list.html Exception Location: /Library/Python/2.7/site-packages/django/template/loader.py in select_template, line 194 Python Executable: /usr/bin/python Python Version: 2.7.2 Python Path: ['/Users/nnn/django_exercises/mysite', '/Users/nnn/py_pkg/lib/python/django_polls-0.1-py2.7.egg', '/Users/nnn/py_pkg/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', '/Library/Python/2.7/site-packages'] Server time: Fri, 26 Jul 2013 16:59:14 -0700 Template-loader postmortem Django tried loading these templates, in this order: - Using loader django.template.loaders.filesystem.Loader: - /Users/nnn/django_exercises/mysite/templates/polls/index.html, polls/poll_list.html (File does not exist) - Using loader django.template.loaders.app_directories.Loader: - /Library/Python/2.7/site-packages/django/contrib/auth/templates/polls/index.html, polls/poll_list.html (File does not exist) - /Library/Python/2.7/site-packages/django/contrib/admin/templates/polls/index.html, polls/poll_list.html (File does not exist) -- 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. For more options, visit https://groups.google.com/groups/opt_out.
Forms with fields created dynamically client side
Hi, I am creating a form for the user to add, edit, and remove all tags in the database. The tag models are handled by taggit. The form will look like like _Tag1_[del] _Tag2_[del] __<--- User enters next tag here [add tag] Clicking add tag will fire some javascript to add a new text input to the form. I trying to create this form in Django to handle the request. This is what I have so far. I am curious if I am going about this the right way. It all seems very... roundabout. Thoughts? One part that bothers me is I must inspect the incoming data to decide how many form elements to create. Coming from PHP, I would create form names with array notation (tags[pk] = name) and iterate over the array during the request. The existing_tag dictionary allows me to map form names to tag objects. The new_tags list allows me to iterate over tag fields that must be created as new tags. class TagsForm(forms.Form): def __init__(self, data=None, *args, **kwargs): super(TagsForm, self).__init__(data, *args, **kwargs) self.existing_tags = {} self.new_tags = [] for tag in Tag.objects.all(): name = 'tag%i' % tag.pk self.fields[name] = forms.CharField( initial=tag.name, required=False) self.existing_tags[name] = tag if data: for name in data: if name.startswith('newtags'): self.fields[name] = forms.CharField(required=False) self.new_tags.append(name) else: name = 'newtags' self.fields[name] = forms.CharField(required=False) self.new_tags.append(name) -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. For more options, visit https://groups.google.com/groups/opt_out.
Re: .filter() and .exclude() don't add up
> So, if one of the fields can be Null, then *neither*: > > queryset.filter(field=value) > > queryset.exclude(field=value) > > will match a record where it's Null? As I understand it, this is correct - it's certainly the way SQL was designed. > In that case, is there a better - more reliable - way than using both > .filter() and .exclude() with the same terms to split a queryset into all > those items that match a filter, and all those that don't? As well as doing the queries above, you can get the nulls by doing queryset.filter(field__isnull=True) and then it's just a matter of deciding which of your two sets the nulls should be included in (probably with a logical OR). There are a number of other approaches as well, but somewhere we'll still have to decide what the meaning of null. My bias is towards making that explicit. The other obvious approach is to find queryset.all() and then the (null-less) set queryset.filter(field=value) and work with them. -- steve http://stevemcconville.com/ -- 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. For more options, visit https://groups.google.com/groups/opt_out.
Re: .filter() and .exclude() don't add up
You really should figure out which record isn't showing up in either sub case and look at it in detail to see if NULLs are involved before you spend time trying to fix a problem that you don't have. You could, for example collect all the ids from the several queries into python sets, union the sub queries, and take the difference of that from the total query. On Fri, Jul 26, 2013 at 5:28 PM, Daniele Procidawrote: > On Fri, Jul 26, 2013, Steve McConville wrote: > > >Firstly (and I don't think this is the cause of the problem) you're > >calling datetime.now() four times, which will give you four different > >datetimes (ie. the queries will not be completely identical). > > Good point, I will address that. > > > Secondly > >SQL uses a 3-valued logic (with null) so if any of the fields you're > >filtering on are nullable you may not be able to rely on the law of > >the excluded middle > > So, if one of the fields can be Null, then *neither*: > > queryset.filter(field=value) > > queryset.exclude(field=value) > > will match a record where it's Null? > > In that case, is there a better - more reliable - way than using both > .filter() and .exclude() with the same terms to split a queryset into all > those items that match a filter, and all those that don't? > > Thanks, > > Daniele > > -- > 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. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- 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. For more options, visit https://groups.google.com/groups/opt_out.
Re: .filter() and .exclude() don't add up
On Fri, Jul 26, 2013, Steve McConvillewrote: >Firstly (and I don't think this is the cause of the problem) you're >calling datetime.now() four times, which will give you four different >datetimes (ie. the queries will not be completely identical). Good point, I will address that. > Secondly >SQL uses a 3-valued logic (with null) so if any of the fields you're >filtering on are nullable you may not be able to rely on the law of >the excluded middle So, if one of the fields can be Null, then *neither*: queryset.filter(field=value) queryset.exclude(field=value) will match a record where it's Null? In that case, is there a better - more reliable - way than using both .filter() and .exclude() with the same terms to split a queryset into all those items that match a filter, and all those that don't? Thanks, Daniele -- 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. For more options, visit https://groups.google.com/groups/opt_out.
Re: or-ing to QuerySets turns INNER into LEFT OUTER joins?
> This is still about 50 times better than the form with Q objects and > LEFT OUTER joins. This is rather unusual. A join in the database should be quite a bit faster than doing things manually, except if the joined tables produce massive amounts of data. This suggests that you're missing useful indexes and/or statistics for your query. mjl -- 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. For more options, visit https://groups.google.com/groups/opt_out.
Django documentation code ?
Is there a way to download just the code examples listed in the Django documentation pages ? VH -- 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. For more options, visit https://groups.google.com/groups/opt_out.
Re: tinymce
See the README at https://github.com/aljosa/django-tinymce On Fri, Jul 26, 2013 at 2:00 PM, Karl Arunachal < kakararunachalserv...@gmail.com> wrote: > Hi, > I want to integrate tinymce in my text area. But i can't find any good > tutorials for it. Can some someone please advice me how to do this. > Thank you. > > -- > 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. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- 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. For more options, visit https://groups.google.com/groups/opt_out.
tinymce
Hi, I want to integrate tinymce in my text area. But i can't find any good tutorials for it. Can some someone please advice me how to do this. Thank you. -- 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. For more options, visit https://groups.google.com/groups/opt_out.
Re: .filter() and .exclude() don't add up
Firstly (and I don't think this is the cause of the problem) you're calling datetime.now() four times, which will give you four different datetimes (ie. the queries will not be completely identical). Secondly SQL uses a 3-valued logic (with null) so if any of the fields you're filtering on are nullable you may not be able to rely on the law of the excluded middle: https://en.wikipedia.org/wiki/Null_(SQL)#Law_of_the_excluded_fourth_.28in_WHERE_clauses.29 On 26 July 2013 16:57, Daniele Procidawrote: > How is this possible? > > # we start with a queryset actual_events > > # get forthcoming_events using filter() > > forthcoming_events = actual_events.filter( > Q(single_day_event = True, date__gte = datetime.now()) | \ > Q(single_day_event = False, end_date__gte = datetime.now()) > ) > > # get previous_events using exclude() and exactly the same terms as above > > previous_events = actual_events.exclude( > Q(single_day_event = True, date__gte = datetime.now()) | \ > Q(single_day_event = False, end_date__gte = datetime.now()) > ) > > # And now: > > # actual_events.count(): 467 > # forthcoming_events.count(): 24 > # previous_events.count():442 > > SInce I have run .filter() and .exclude() with identical terms, should they > not between them contain all the items in the queryset they acted upon, > *whatever* the terms used? > > Daniele > > -- > 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. > For more options, visit https://groups.google.com/groups/opt_out. > > -- steve http://stevemcconville.com/ -- 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. For more options, visit https://groups.google.com/groups/opt_out.
Re: or-ing to QuerySets turns INNER into LEFT OUTER joins?
Hi Tom, thank you very much for your detailed reply, it helped at lot! Am 25.07.2013 19:00, schrieb Tom Evans: [...] As an example you can play around with, pick one user who has log entries, and remove all their departments from STAFF_BEREICHE. This user should then be found with the slow query with LEFT OUTER joins, but not with the fast query with INNER joins [...] Yes, I can reproduce this, and also for the opposite case, where a STAFF member has no entries in the related ERFASST table. And although I've clipped most of your text in the quote above for brevity, your text really made me understand the background and reasoning, too! :-D Now with correctness established, this leaves me with the performance problem. The formulation with the OR and the LEFT OUTER joins is indeed what we semantically need (also see below, about Erfasst and logging ;) ). The best that I could think of so far is to run the individual queries individually, combine the results in Python code (the "OR" operation), then (as we need a QuerySet at this place in the code for further filtering) run another query with `.filter(id__in=ManuallyCombinedResults)`: S_a = set(Staff.objects. \ filter(bereiche=SomeDep).values_list('id', flat=True)) S_b = set(Staff.objects. \ filter(erfasst__datum__gte=FirstDay, erfasst__datum__lte=LastDay, erfasst__bereich=SomeDep).values_list('id', flat=True)) Q_a_or_b = Staff.objects.filter(id__in=S_a | S_b).distinct() This is still about 50 times better than the form with Q objects and LEFT OUTER joins. (Do you see a way to optimize this even further (in the Django ORM)?) My initial assumption was that the OR in the all-in-one query would not be much slower than the individual queries, and was really surprised to learn otherwise... * Erfasst is meaning logging here, right? Reaching the limits of my German :) Translated verbatim, "Erfasst" means "committed" or "recorded" -- which obviously is a really stupid name for a database table. Alas, this is the legacy that I got when I overtook the original PHP project, and backwards-compatibility has so far kept me from updating the name. What we really are recording here are "workdays". In my attempt to keep the examples in my initial post both easy to understand and correct, I only translated the table name for STAFF, but felt that I'd lose consistency and thus correctness if things got more involved if I translated ERFASST as well (especially with backwards relation names etc.) So the above is really an attempt to find all STAFF members who are assigned to a certain department regularly (via STAFF_BEREICHE), "OR" those who have spent a workday in that department in the given time range. (So new staff members who have not yet spent a single workday anywhere would promptly be missing from any report and form with the INNER-joins-only query...) Tom, many thanks for your help! Best regards, Carsten -- Dipl.-Inf. Carsten Fuchs Carsten Fuchs Software Industriegebiet 3, c/o Rofu, 55768 Hoppstädten-Weiersbach, Germany Internet: http://www.cafu.de | E-Mail: i...@cafu.de Cafu - the open-source game and graphics engine for multiplayer 3D action -- 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. For more options, visit https://groups.google.com/groups/opt_out.
Re: Django throws an exception when I add data from admin interface
On Fri, Jul 26, 2013 at 4:22 PM, Yu Yangwrote: > It is a blog app, I have created a Article model and Tag model. when I add > data to Article table from Admin interface, the data is stored to database, > but if I click the link to change the entry, it throws an exception "string > indices must be integers, not str", the traceback is as follows: > Environment: > > > Request Method: GET > Request URL: http://localhost:8000/admin/blog/article/1/ > > Django Version: 1.5.1 > Python Version: 2.7.3 > Installed Applications: > ('django.contrib.auth', > 'django.contrib.contenttypes', > 'django.contrib.sessions', > 'django.contrib.sites', > 'django.contrib.messages', > 'django.contrib.staticfiles', > 'django.contrib.admin', > 'blog') > Installed Middleware: > ('django.middleware.common.CommonMiddleware', > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.middleware.csrf.CsrfViewMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware', > 'django.contrib.messages.middleware.MessageMiddleware') > > > Traceback: > File > "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/core/handlers/base.py" > in get_response > 115. response = callback(request, *callback_args, > **callback_kwargs) > File > "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/contrib/admin/options.py" > in wrapper > 372. return self.admin_site.admin_view(view)(*args, > **kwargs) > File > "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/utils/decorators.py" > in _wrapped_view > 91. response = view_func(request, *args, **kwargs) > File > "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/views/decorators/cache.py" > in _wrapped_view_func > 89. response = view_func(request, *args, **kwargs) > File > "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" > in inner > 202. return view(request, *args, **kwargs) > File > "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/utils/decorators.py" > in _wrapper > 25. return bound_func(*args, **kwargs) > File > "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/utils/decorators.py" > in _wrapped_view > 91. response = view_func(request, *args, **kwargs) > File > "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/utils/decorators.py" > in bound_func > 21. return func(self, *args2, **kwargs2) > File > "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/db/transaction.py" > in inner > 223. return func(*args, **kwargs) > File > "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/contrib/admin/options.py" > in change_view > 1112. form = ModelForm(instance=obj) > File > "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/forms/models.py" > in __init__ > 244. object_data = model_to_dict(instance, opts.fields, > opts.exclude) > File > "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/forms/models.py" > in model_to_dict > 129. data[f.name] = > list(f.value_from_object(instance).values_list('pk', flat=True)) > File > "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/db/models/fields/related.py" > in value_from_object > 1333. return getattr(obj, self.attname).all() > File > "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/db/models/manager.py" > in all > 128. return self.get_query_set() > File > "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/db/models/fields/related.py" > in get_query_set > 612. return > self.instance._prefetched_objects_cache[self.prefetch_cache_name] > > Exception Type: TypeError at /admin/blog/article/1/ > Exception Value: string indices must be integers, not str > > > the code of Article model and Tag model is as follows: > > > class Tag(models.Model): > name = models.CharField(max_length=50, unique=True, verbose_name='标签') > slug = models.SlugField() > > def __unicode__(self): > return self.name > > class Meta: > verbose_name = '标签' > verbose_name_plural = '标签' > > @models.permalink > def get_absolute_url(self): > return ('blog_tag', (), {'idx': self.id, 'slug': self.slug}) > > > # Create your models here. > class Article(models.Model): > """ > the model for blog article > """ > STATUS_CHOICE = ( > (1, '编辑'), > (2, '完成'), > (3, '失效'), > ) > title = models.CharField(max_length=100, verbose_name='标题') > slug = models.SlugField(max_length=100) >
Django throws an exception when I add data from admin interface
It is a blog app, I have created a Article model and Tag model. when I add data to Article table from Admin interface, the data is stored to database, but if I click the link to change the entry, it throws an exception "string indices must be integers, not str", the traceback is as follows: Environment: Request Method: GET Request URL: http://localhost:8000/admin/blog/article/1/ Django Version: 1.5.1 Python Version: 2.7.3 Installed Applications: ('django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.admin', 'blog') Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware') Traceback: File "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response 115. response = callback(request, *callback_args, **callback_kwargs) File "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper 372. return self.admin_site.admin_view(view)(*args, **kwargs) File "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view 91. response = view_func(request, *args, **kwargs) File "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func 89. response = view_func(request, *args, **kwargs) File "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner 202. return view(request, *args, **kwargs) File "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper 25. return bound_func(*args, **kwargs) File "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view 91. response = view_func(request, *args, **kwargs) File "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func 21. return func(self, *args2, **kwargs2) File "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/db/transaction.py" in inner 223. return func(*args, **kwargs) File "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in change_view 1112. form = ModelForm(instance=obj) File "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/forms/models.py" in __init__ 244. object_data = model_to_dict(instance, opts.fields, opts.exclude) File "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/forms/models.py" in model_to_dict 129. data[f.name] = list(f.value_from_object(instance).values_list('pk', flat=True)) File "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/db/models/fields/related.py" in value_from_object 1333. return getattr(obj, self.attname).all() File "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/db/models/manager.py" in all 128. return self.get_query_set() File "/home/yangyu/.virtualenvs/django-blog/local/lib/python2.7/site-packages/django/db/models/fields/related.py" in get_query_set 612. return self.instance._prefetched_objects_cache[self.prefetch_cache_name] Exception Type: TypeError at /admin/blog/article/1/ Exception Value: string indices must be integers, not str the code of Article model and Tag model is as follows: class Tag(models.Model): name = models.CharField(max_length=50, unique=True, verbose_name='标签') slug = models.SlugField() def __unicode__(self): return self.name class Meta: verbose_name = '标签' verbose_name_plural = '标签' @models.permalink def get_absolute_url(self): return ('blog_tag', (), {'idx': self.id, 'slug': self.slug}) # Create your models here. class Article(models.Model): """ the model for blog article """ STATUS_CHOICE = ( (1, '编辑'), (2, '完成'), (3, '失效'), ) title = models.CharField(max_length=100, verbose_name='标题') slug = models.SlugField(max_length=100) content = models.TextField(verbose_name='内容') created_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间") modified_time = models.DateTimeField(default=datetime.now, verbose_name="修改时间") tags
.filter() and .exclude() don't add up
How is this possible? # we start with a queryset actual_events # get forthcoming_events using filter() forthcoming_events = actual_events.filter( Q(single_day_event = True, date__gte = datetime.now()) | \ Q(single_day_event = False, end_date__gte = datetime.now()) ) # get previous_events using exclude() and exactly the same terms as above previous_events = actual_events.exclude( Q(single_day_event = True, date__gte = datetime.now()) | \ Q(single_day_event = False, end_date__gte = datetime.now()) ) # And now: # actual_events.count(): 467 # forthcoming_events.count(): 24 # previous_events.count():442 SInce I have run .filter() and .exclude() with identical terms, should they not between them contain all the items in the queryset they acted upon, *whatever* the terms used? Daniele -- 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. For more options, visit https://groups.google.com/groups/opt_out.
Re: ajax and django
https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ajax []'s Lucas Magnum. 2013/7/26 Lucas Magnum> Are you passing crsf_token in ajax post? > > []'s > > Lucas Magnum. > > > 2013/7/26 heni yemun > >> Hi, >> I'm trying to get a django project interact with ajax based site. The >> problem is that when i use the send function to send a POST data >> asynchronously the django app returns a 500 code and the server doesn't do >> anything. How do i correct this? >> >> -- >> 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. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > -- 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. For more options, visit https://groups.google.com/groups/opt_out.
Re: ajax and django
Are you passing crsf_token in ajax post? []'s Lucas Magnum. 2013/7/26 heni yemun> Hi, > I'm trying to get a django project interact with ajax based site. The > problem is that when i use the send function to send a POST data > asynchronously the django app returns a 500 code and the server doesn't do > anything. How do i correct this? > > -- > 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. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- 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. For more options, visit https://groups.google.com/groups/opt_out.
ajax and django
Hi, I'm trying to get a django project interact with ajax based site. The problem is that when i use the send function to send a POST data asynchronously the django app returns a 500 code and the server doesn't do anything. How do i correct this? -- 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. For more options, visit https://groups.google.com/groups/opt_out.
Re: Avoid unbounded memory consumption when running `manage.py test`
On Thursday, July 18, 2013 7:30:55 PM UTC-7, Matt McClure wrote: > 1. TestSuite. Here's a minimal hack to release the reference that > TestSuite would otherwise hold after a TestCase runs until the remainder of > the suite had finished. > > +self._tests.remove(test) > That turns out to be a bad idea because it modifies a list inside a loop iterating over it, making the loop skip items it should visit. Here's an updated change that doesn't suffer from that problem: diff --git a/django/utils/unittest/suite.py b/django/utils/unittest/suite.py index f39569b..8530200 100644 --- a/django/utils/unittest/suite.py +++ b/django/utils/unittest/suite.py @@ -1,5 +1,6 @@ """TestSuite""" +import gc import sys import unittest from django.utils.unittest import case, util @@ -96,7 +97,11 @@ class TestSuite(BaseTestSuite): # private methods def _wrapped_run(self, result, debug=False): -for test in self: +while True: +try: +test = self._tests.pop(0) +except IndexError: +break if result.shouldStop: break @@ -116,6 +121,7 @@ class TestSuite(BaseTestSuite): test(result) else: test.debug() +#gc.collect() def _handleClassSetUp(self, test, result): previousClass = getattr(result, '_previousTestClass', None) -- 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. For more options, visit https://groups.google.com/groups/opt_out.
Test using different database
Hi, I have two databases on my settings file. One is sqlite and the other is postgis. It is a big project so some developers use sqllite and a few are using postgis. Now, when I try ./manage.py test command, I get the following, Creating test database for alias 'default'... AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type' - Is there a way to issue a command that contains the alias for the postgis database? I am looking for something like " ./manage.py test --database='spatial_db' " or similar. I have been looking around documentation and examples but haven't been able to come around this. Here is what I have been looking, https://docs.djangoproject.com/en/dev/topics/testing/overview/#the-test-database https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/unit-tests/ https://docs.djangoproject.com/en/dev/topics/testing/advanced/#topics-testing-advanced-multidb http://stackoverflow.com/questions/4650509/different-db-for-testing-in-django Any suggestions would be appreciated! Thanks in advance, A -- 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. For more options, visit https://groups.google.com/groups/opt_out.
Re: Can I only have one "get_queryset" per Viewpage?
Thanks Tom that got rid of the Debug message. My views.py code and index.html code now looks like this. But how exactly do I send my IndexView query results (filter1, 2 and 3) to my index.html template file? The only thing I see on the webpage is this result: No polls are available. *views.py* from polls.models import Word, Pronunciation, Altword #___ class IndexView(generic.ListView): template_name = 'polls/index.html' context_object_name = 'context' def get_queryset(self): def get_context_data(**kwargs): context = super(IndexView, self).get_context_data(**kwargs) # Filter 1 filter_1 = Word.objects.filter(pub_date__lte=timezone.now() ).order_by('-pub_date')[:5] # Filter 2 filter_2 = Word.objects.filter(translation='') # Filter 3 filter_3 = Pronunciation.objects.filter(wordfield__translation='') context.update({ "filter_1": filter_1, "filter_2": filter_2, "filter_3": filter_3 }) return context #___ *index.html* index.html {% if context %} {% for word in context %} {{ word.wordfield }} {% endfor %} {% else %} No polls are available. {% endif %} On Friday, July 26, 2013 11:29:54 AM UTC+2, Tom Evans wrote: > > On Fri, Jul 26, 2013 at 9:57 AM, Pepsodent Cola >> wrote: > > > > I am having trouble understanding what the Debug wants me to fix and how > > to fix it? > > Isn't my models already defined? Isn't my queryset already defined in > > variables filter_1, 2 and 3? > > > > Exception Type: ImproperlyConfigured > > Exception Value: > > > > 'IndexView' must define 'queryset' or 'model' > > You must provide get_queryset() method, this will be represented in > the template context by whatever name you set in context_object_name. > If you want extra objects in the template context, you can add them by > overriding get_context_data(), but you must still provide the > get_queryset() method, it is not optional. > > Cheers > > Tom > -- 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. For more options, visit https://groups.google.com/groups/opt_out.
Re: Search from database
On Fri, Jul 26, 2013 at 12:10 PM, Kamal Kaurwrote: > These commands don't extract the files: > http://django-haystack.readthedocs.org/en/latest/installing_search_engines.html Installed with this: http://mirror.metrocast.net/apache/lucene/solr/4.4.0/solr-4.4.0.tgz -- Kamaljeet Kaur kamalkaur188.wordpress.com facebook.com/kaur.188 -- 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. For more options, visit https://groups.google.com/groups/opt_out.
Re: Can I only have one "get_queryset" per Viewpage?
On Fri, Jul 26, 2013 at 9:57 AM, Pepsodent Colawrote: > > I am having trouble understanding what the Debug wants me to fix and how > to fix it? > Isn't my models already defined? Isn't my queryset already defined in > variables filter_1, 2 and 3? > > Exception Type: ImproperlyConfigured > Exception Value: > > 'IndexView' must define 'queryset' or 'model' You must provide get_queryset() method, this will be represented in the template context by whatever name you set in context_object_name. If you want extra objects in the template context, you can add them by overriding get_context_data(), but you must still provide the get_queryset() method, it is not optional. Cheers Tom -- 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. For more options, visit https://groups.google.com/groups/opt_out.
Re: Can I only have one "get_queryset" per Viewpage?
I am having trouble understanding what the Debug wants me to fix and how to fix it? Isn't my models already defined? Isn't my queryset already defined in variables filter_1, 2 and 3? Exception Type: ImproperlyConfigured Exception Value: *'IndexView' must define 'queryset' or 'model'* Exception Location: /usr/local/lib/python2.7/dist-packages/django/views/generic/list.py in get_queryset, line 35 *views.py* from polls.models import Word, Pronunciation #___ class IndexView(generic.ListView): template_name = 'polls/index.html' #context_object_name = 'latest_poll_list' # def get_queryset(self): def get_context_data(**kwargs): context = super(IndexView, self).get_context_data(**kwargs) # Filter 1 filter_1 = Word.objects.filter(pub_date__lte=timezone.now() ).order_by('-pub_date')[:5] # Filter 2 filter_2 = Word.objects.filter(translation='') # Filter 3 filter_3 = Pronunciation.objects.filter(wordfield__translation='') context.update({ "filter_1": filter_1, "filter_2": filter_2, "filter_3": filter_3 }) return context #___ On Tuesday, July 23, 2013 8:17:36 AM UTC+2, Tundebabzy wrote: > > Override your get method but it's easier to override the get_context_data > method like > # From my head > def get_context_data(**kwargs): > context = super(IndexView, self).get_context_data(**kwargs) > #filter1 is already present as latest_poll_list in the context > filter2 = Word.blah() > filter3 = Word.blah_blah() > context.update({ > "filter2": filter2, > "filter3": filter3 > }) > return context > > Sent from my Windows Phone > -- > From: Pepsodent Cola > Sent: 7/22/2013 9:47 PM > To: django...@googlegroups.com > Subject: Re: Can I only have one "get_queryset" per Viewpage? > > I'm having difficulty understanding the abstract explanations in that > documentation. > Could you or somebody else explain this, by showing by example using my > code examples? > > *views.py* > > class IndexView(generic.ListView): > template_name = 'polls/index.html' > context_object_name = *'latest_poll_list'* > > def get_queryset(self): > """ > Return the last five published polls > (not including those set to be published in the future). > """ > return Word.objects.filter( > pub_date__lte=timezone.now() > ).order_by('-pub_date')[:5] > > *### Filter 2* > #Word.objects.filter(translation='') > *### Filter 3* > #Pronunciation.objects.filter(wordfield__translation='') > > > > > *index.html* > > index.html > > {% if latest_poll_list %} > > {% for word in *latest_poll_list* %} > {{ word.wordfield > }} > {% endfor %} > > {% else %} > No polls are available. > {% endif %} > > > > How should I write my IndexView class so that Filter 1, 2 and 3 list > results are then sent to my index.html template file? > > > > > On Monday, July 22, 2013 2:03:59 PM UTC+2, macndesign wrote: >> >> Hi, you can separate your querysets in get_context_data method. >> See: >> https://docs.djangoproject.com/en/dev/ref/class-based-views/mixins-simple/#django.views.generic.base.ContextMixin.get_context_data >> >> >> 2013/7/22 Pepsodent Cola>> >>> Hi, >>> >>> Can I only have one "get_queryset" for each Viewpage? >>> If I wanted to add another database list on the same Viewpage how would >>> that code look like for my Django *views.py* file? >>> >>> Example: >>> https://docs.djangoproject.com/en/1.5/intro/tutorial04/#amend-views >>> >>> from polls.models import Choice, Poll >>> >>> class IndexView(generic.ListView): >>> template_name = 'polls/index.html' >>> *context_object_name = 'latest_poll_list'* >>> >>> *def get_queryset(self):* >>> """Return the last five published polls.""" >>> return Poll.objects.order_by('-pub_date')[:5] >>> >>> >>> >>> I mean will "context_object_name" be able to separate between several >>> "get_queryset(self)"? >>> Because I want to have several different poll_lists on the same Viewpage. >>> >>> context_object_name = 'latest_poll_list' >>> >>> -- >>> 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...@googlegroups.com. >>> To post to this group, send email to django...@googlegroups.com. >>> Visit this group at http://groups.google.com/group/django-users. >>> For more options, visit https://groups.google.com/groups/opt_out. >>> >>> >>> >> >> >> >> -- >> Att. *Mário Araújo Chaves Neto* >> *Programmer, Designer and U.I. Engineer* >> * >> * >> *MBA in Design Digital* - 2008 -
Re: Problem with chaining filters
Thanks Andrew, I will practice more on doing Many-to-one relationships. https://docs.djangoproject.com/en/1.5/topics/db/examples/many_to_one/ On Monday, July 22, 2013 1:45:49 PM UTC+2, Andrew Simpson wrote: > > Perhaps something like this would give you what you need: > Pronunciation.objects.filter(word__translation='') > -- 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. For more options, visit https://groups.google.com/groups/opt_out.
Re: Search from database
On Wed, Jul 24, 2013 at 5:15 AM, Amirouche Boubekkiwrote: > Apache solr or ElasticSearch: yes Is this the right method for installation? What is the need to adduser? http://www.cubrid.org/wiki_tutorials/entry/install-apache-solr-on-ubuntu These commands don't extract the files: http://django-haystack.readthedocs.org/en/latest/installing_search_engines.html -- Kamaljeet Kaur kamalkaur188.wordpress.com facebook.com/kaur.188 -- 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. For more options, visit https://groups.google.com/groups/opt_out.