dictionary update sequence
Hi, I am getting the following error when the server tries to load one of my templates and I am not sure what the problem is: dictionary update sequence element #0 has length 1; 2 is required The error occurs at the following line in my template: However, I thought I was already passing it both of those arguments (geneset.user and geneset.slug). Does that have anything to do with it? I also recently installed the Django tastypie API - Could that be causing the problem at all? Many thanks! Rene -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Django Tastypie: Getting MultipleObjects returned
Hey everyone, While using the Tastypie API, I have been getting a MultipleObjectsReturned error somehow when obj_get gets called. I feed a Resource URI to a ToManyField for one of the resources and somehow I get this error. This has me really frustrated, since I thought that by giving it a URI (ex: " /api/v1/gene/1/ "), it would only return one object. Creating and saving objects works fine without the Tastypie API. These are the involved resources: class GeneResource(ModelResource): entrezid = fields.IntegerField(attribute = 'entrezid') genesets = fields.ToManyField("genesets.api.resources.GeneSetResource", 'genesets', null=True, blank=True) class Meta: queryset = Gene.objects.all() resource_name = 'gene' filtering = {'entrezid': ALL, } class GeneSetResource(ModelResource): title= fields.CharField(attribute='title') user = fields.ForeignKey(UserResource, 'user', full=True) organism = fields.ToOneField(OrganismResource, 'organism', full=True) genes= fields.ToManyField(GeneResource, 'genes', related_name='genesets', full=True) class Meta: queryset = GeneSet.objects.all() resource_name = 'geneset' authorization = Authorization() filtering = { 'user': ALL_WITH_RELATIONS, 'title': ALL, 'genes': ALL_WITH_RELATIONS, } And this is the error I get: "Traceback (most recent call last): File "/home/rene/Documents/venv/local/lib/python2.7/site-packages/tastypie/resources.py", line 217, in wrapper response = callback(request, *args, **kwargs) File "/home/rene/Documents/venv/local/lib/python2.7/site-packages/tastypie/resources.py", line 459, in dispatch_list return self.dispatch('list', request, **kwargs) File "/home/rene/Documents/venv/local/lib/python2.7/site-packages/tastypie/resources.py", line 491, in dispatch response = method(request, **kwargs) File "/home/rene/Documents/venv/local/lib/python2.7/site-packages/tastypie/resources.py", line 1357, in post_list updated_bundle = self.obj_create(bundle, **self.remove_api_resource_names(kwargs)) File "/home/rene/Documents/venv/local/lib/python2.7/site-packages/tastypie/resources.py", line 2150, in obj_create return self.save(bundle) File "/home/rene/Documents/venv/local/lib/python2.7/site-packages/tastypie/resources.py", line 2300, in save m2m_bundle = self.hydrate_m2m(bundle) File "/home/rene/Documents/venv/local/lib/python2.7/site-packages/tastypie/resources.py", line 964, in hydrate_m2m bundle.data[field_name] = field_object.hydrate_m2m(bundle) File "/home/rene/Documents/venv/local/lib/python2.7/site-packages/tastypie/fields.py", line 853, in hydrate_m2m m2m_hydrated.append(self.build_related_resource(value, **kwargs)) File "/home/rene/Documents/venv/local/lib/python2.7/site-packages/tastypie/fields.py", line 653, in build_related_resource return self.resource_from_uri(self.fk_resource, value, **kwargs) File "/home/rene/Documents/venv/local/lib/python2.7/site-packages/tastypie/fields.py", line 573, in resource_from_uri obj = fk_resource.get_via_uri(uri, request=request) File "/home/rene/Documents/venv/local/lib/python2.7/site-packages/tastypie/resources.py", line 838, in get_via_uri return self.obj_get(bundle=bundle, **self.remove_api_resource_names(kwargs)) File "/home/rene/Documents/venv/local/lib/python2.7/site-packages/tastypie/resources.py", line 2131, in obj_get raise MultipleObjectsReturned("More than '%s' matched '%s'." % (self._meta.object_class.__name__, stringified_kwargs)) MultipleObjectsReturned: More than 'Gene' matched ''. " Any ideas of what is going on?? Thanks! Much appreciated!! -- 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 Tastypie: Getting MultipleObjects returned
Hey everyone, So I figured out what was going on in my code - apparently, when adding items to a ToManyField through the API, this requires a specific format, namely: ["api/v1/exampleResource/1/","api/v1/exampleResource/2/","api/v1/exampleResource/3/"] Note the lack of any spacing, the quotations around each resource URI, and the enclosing brackets. I had to fiddle around with my JavaScript code so that this was the format it returned to the API when posting the related resource. Hope this will help someone if they get stuck in the same place! Rene -- 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 model(s) silently fails to sync to the DB ( for no apparent reason )
Hey Doug, Any chance you haven't included those models in the INSTALLED_APPS in your settings.py file? Best, Rene On Monday, October 7, 2013 9:40:33 PM UTC-4, Doug S wrote: > > I don't think I'm making a rookie mistake, I've looked over my code > several times. > I've got two pretty simple django models that are just failing to sync to > the db > during the syncdb there are no errors, even with --verbosity 3 > When I try to make a relation to them I get an error saying the models > either don't exist or a re abstract > In fact when I examine the DB, they are not there. > syncdb is attempting to sync models before and after these 2 models in the > same file. > I've dropped my DB and started from scratch several times > I don't know how to debug this issue because I don't know how syncdb works > under the covers and what can go wrong. > Here are my models, they look pretty simple to me: > > class DirEnumVal(models.Model): > > str_val = models.CharField(max_length=64, default='') > > def unicode(self): > > return self.str_val > > class DirAttr(models.Model): > > > > BOOL = 'BOOL' > > MONO = 'MONO' > > SCAL = 'SCAL' > > ENUM = 'ENUM' > > > > TYPES = ( > > (BOOL,'Boolean'), > > (MONO,'Monomial'), > > (SCAL,'Scalar'), > > (ENUM,'Enumeration'), > > ) > > > > val_type = models.CharField(max_length=4, choices=TYPES) > > val_key = models.CharField(max_length=32) > > default_bool = models.BooleanField(default=True) > > default_num = models.IntegerField(default = 0) > > default_float = models.FloatField(default=1.0) > > enum_choices = models.ManyToManyField(DirEnumVal, null=True, blank= > True) > > default_choice = models.CharField(max_length=64, default='') > > required = models.BooleanField(default=True) > > > > def unicode(self): > > return '{k} :=> {t} ( default = {d} )'.format( > > k=self.val_key, t=self.val_type, d=self.default()) > > I am using a pattern with multiple model files for a single app > > my dir structure is: > > >app > > > models > > - __init__.py > > - model_file1.py > > - model_file2.py > > and in my __init__.py I've got code to pull all the models together into > one module: app.models > > from __future__ import absolute_import > > from .model_file1 import model1a,model1b,model1c > > from .model_file2 import model2a,model2b,model2c > > This way of importing the models has been working long before this trouble > of models not being synched came up. > > When I access the django project and settings through a python shell I can > import the models and instatiate them > > but when I save them, PostGres gives me this error: > > DatabaseError: current transaction is aborted, commands ignored until end of > transaction block > > > This problem surfaced after I installed django-categories and set up some > category models. > > I had some trouble at first setting that up but I've got the BaseCategory > subclasses behaving nicely now > > and have started with a fresh DB. > > At some point when I was getting django categories to work there was an error > when I synched the DB > > that said something about an unexcepted special character being somewhere in > my code or the django-categories code. > > That seemed suspicious but that doesn't show up anymore and I'm using a fresh > DB. > > > Does anybody see anything obvious or know what type of problems can cause > syncdb to ignore models? > > I'm running out of ideas about what is wrong > > I'm on Django 1.5 using PostGreSQL & MacOS Lion > > Best Doug > -- 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/29eb0976-3a4b-4210-a78d-aab8c296180a%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: IndentationError :Unexpected Indent
Ditto from what Andreas said - Python is very sensitive to indentation. If the method 'was_published_recently' is part of the Poll model, then there should be the same amount of indentations before 'def was_published...' as for the 'def __unicode__' method. Then, for uniformity's sake (even though it is technically not necessary), the 'return self.pub_date...' line should also have the same number of indents FROM the indent where the 'def was_published...' method line starts (in this case 3), like so: class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') def __unicode__(self): return self.question def was_published_recently (self): return self.pub_date > = timezone.now() - datetime.timedelta(days=1) This is to indicate it is IN the 'was_published_recently' method. Cheers. On Monday, April 28, 2014 1:55:27 AM UTC-4, Kelvin Mwangi wrote: > > I have been following up on the tutorial on Python version 1.6 and I got > stuck at an indentation error I can't seem to debug. Its under the first > tutorial of creating Django application and I modified my polls\models.py > file to look like this; > > from django.db import models > import datetime > from django.utils import timezone > > class Poll(models.Model): > question = models.CharField(max_length=200) > pub_date = models.DateTimeField('date published') > def __unicode__(self): > return self.question > def was_published_recently (self): > return self.pub_date > = timezone.now() - datetime.timedelta(days=1) > > class Choice(models.Model): > poll = models.ForeignKey(Poll) > choice_text = models.CharField(max_length=200) > votes = models.IntegerField(default=0) > def __unicode__(self): > return self.choice_text > > I keep getting an error at that line that starts with "def > was_published_recently.." and can't seem to debug the error. Can anyone > kindly help me here? I'm stuck. :( > > -- 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/725f3014-2e81-4af5-9ccb-41cc696191b9%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: I can't run django server nor activate the virtualenv
Hi Fred - So if you can't activate your virtualenv, and you installed Django in that virtualenv, that is likely the root of your problem, because without it, none of the modules will appear as installed and you will not be able to run the server (or access the python manage.py shell, etc). I would first figure out why you can't activate the virtual environment -- what is the error when you try to activate it? Rene On Monday, April 28, 2014 6:03:40 AM UTC-4, Fred DJar wrote: > > > > > *Hello guys, i'm a newbie so bear with me :)I have installed python 2.7 > and django 1.6 on my desktop (ubuntu 14)but i can't run the application or > activate the virtualenv* > > *this is the message i got:* > ubuntu@ubuntu:~/Downloads/saf$ python manage.py runserver > Traceback (most recent call last): > File "manage.py", line 10, in > execute_from_command_line(sys.argv) > File > "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", > line 399, in execute_from_command_line > utility.execute() > File > "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", > line 392, in execute > self.fetch_command(subcommand).run_from_argv(self.argv) > File > "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", > line 242, in run_from_argv > self.execute(*args, **options.__dict__) > File > "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", > line 280, in execute > translation.activate('en-us') > File > "/usr/local/lib/python2.7/dist-packages/django/utils/translation/__init__.py", > > line 130, in activate > return _trans.activate(language) > File > "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py", > > line 188, in activate > _active.value = translation(language) > File > "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py", > > line 177, in translation > default_translation = _fetch(settings.LANGUAGE_CODE) > File > "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py", > > line 159, in _fetch > app = import_module(appname) > File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", > line 40, in import_module > __import__(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. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c48bd8cd-4978-4583-ae76-33583e11e848%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: I can't run django server nor activate the virtualenv
Hi Fred, Yes, definitely, I think you should run it on a Ubuntu terminal - I'm not that familiar with the Windows terminal On Monday, April 28, 2014 10:10:29 AM UTC-4, Fred DJar wrote: > > Thanks Rene > The virtualenv was created in Ubuntu but now i'm running windows, should i > run it in Ubuntu because i've noticed that virtualenv folder structure > differentiate from Ubuntu to windows > this is the message i got from the prompt command: activate is not > recognized as an internal or external command, operable program or batch > file > > On Monday, 28 April 2014 11:03:40 UTC+1, Fred DJar wrote: >> >> >> >> >> *Hello guys, i'm a newbie so bear with me :)I have installed python 2.7 >> and django 1.6 on my desktop (ubuntu 14)but i can't run the application or >> activate the virtualenv* >> >> *this is the message i got:* >> ubuntu@ubuntu:~/Downloads/saf$ python manage.py runserver >> Traceback (most recent call last): >> File "manage.py", line 10, in >> execute_from_command_line(sys.argv) >> File >> "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", >> line 399, in execute_from_command_line >> utility.execute() >> File >> "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", >> line 392, in execute >> self.fetch_command(subcommand).run_from_argv(self.argv) >> File >> "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", >> line 242, in run_from_argv >> self.execute(*args, **options.__dict__) >> File >> "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", >> line 280, in execute >> translation.activate('en-us') >> File >> "/usr/local/lib/python2.7/dist-packages/django/utils/translation/__init__.py", >> >> line 130, in activate >> return _trans.activate(language) >> File >> "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py", >> >> line 188, in activate >> _active.value = translation(language) >> File >> "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py", >> >> line 177, in translation >> default_translation = _fetch(settings.LANGUAGE_CODE) >> File >> "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py", >> >> line 159, in _fetch >> app = import_module(appname) >> File >> "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line >> 40, in import_module >> __import__(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. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5e619bec-0dee-4481-989a-27ceb4dff0ff%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Can u tell me how to build restful api project in django
I have found django-tastypie very useful to create a REST API: https://github.com/django-tastypie/django-tastypie Here are the docs: http://django-tastypie.readthedocs.org/en/latest/index.html#quick-start Best, Rene On Friday, August 14, 2015 at 10:22:40 AM UTC-4, HARSHIT GARG wrote: > > I am getting the following error: > > ImportError: rest_framework doesn't look like a module path > -- 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/ec56e753-1431-482f-ad41-7ec6b293de52%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Django-tastypie checking of csrf token in requests
Hi everyone, We have a REST API built using django-tastypie, which most of our users access through our web application. However, we do have users that make requests to the API programmatically (using the python 'requests' library, for example) and use an OAuth token to do so (we have already set up our Tastypie API to do this OAuth authentication). How does Tastypie check for the csrf token, and does anybody have experience modifying the mechanism so that it does check it when users are in a session using the web application but does not require it if users are accessing programmatically AND have a valid OAuth token? Thank you! Rene -- 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/a2bfde34-18e9-4df0-b50c-cfaea48b1d5c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.