| Issue 12: | Error: object has no attribute 'n' | |
| 2 people starred this issue and may be notified of changes. | Back to list |
What steps will reproduce the problem?
1. Trying to save an entry into a model (that has been registered in mptt
using mptt.register()) using the save method model_instance.save()
2.
3.
What is the expected output? What do you see instead?
The expected output was simply a saving of the instance. But instead I get
the error mentioned in the title
What version of the product are you using? On what operating system?
mptt version 2.0... on windows xp
Please provide any additional information below.
Here is the full info...
Used the model provided in the model documentation of mptt...
class Genre(models.Model):
name = models.CharField(max_length=50, null=False, blank=False,
unique=True)
description = models.TextField(max_length=250, null=True, blank=True,
unique=False)
parent = models.ForeignKey('self', null=True, blank=True,
related_name='children')
def __unicode__(self):
return self.name
class Meta:
verbose_name_plural = 'Categories'
class Admin:
pass
try:
mptt.register(Genre,order_insertion_by="name")
except:
print "error hohoha...ignored..."
I have syncdbed..and the table structure looks ok, i.e. the additional
fields are added as promised by mptt...so the table structure is (from
sqlite3 dump table command)
BEGIN TRANSACTION;
CREATE TABLE "offers_genre" (
"id" integer NOT NULL PRIMARY KEY,
"name" varchar(50) NOT NULL UNIQUE,
"description" text NULL,
"parent_id" integer NULL,
"lft" integer unsigned NOT NULL,
"rght" integer unsigned NOT NULL,
"tree_id" integer unsigned NOT NULL,
"level" integer unsigned NOT NULL
);
CREATE INDEX "offers_genre_parent_id" ON "offers_genre" ("parent_id");
CREATE INDEX "offers_genre_lft" ON "offers_genre" ("lft");
CREATE INDEX "offers_genre_rght" ON "offers_genre" ("rght");
CREATE INDEX "offers_genre_tree_id" ON "offers_genre" ("tree_id");
CREATE INDEX "offers_genre_level" ON "offers_genre" ("level");
COMMIT;
#what I am trying to do:
on a python shell trying to put some data into the table...
g1=Genre(name="Rock", description="Music with an attitude");and save it
g1.save()
but the save is giving me this error...
AttributeError Traceback (most recent call last)
C:\sebsib\<ipython console> in <module>()
C:\Python25\lib\site-packages\django\db\models\base.py in save(self, raw)
210
211 def save(self, raw=False):
--> 212 dispatcher.send(signal=signals.pre_save, sender=self.__class__,
instance=self)
213
214 non_pks = [f for f in self._meta.fields if not f.primary_key]
C:\Python25\lib\site-packages\django\dispatch\dispatcher.py in send(signal,
send
er, *arguments, **named)
358 sender=sender,
359 *arguments,
--> 360 **named
361 )
362 responses.append((receiver, response))
C:\Python25\lib\site-packages\django\dispatch\robustapply.py in
robustApply(rece
iver, *arguments, **named)
43 # remove unacceptable arguments.
44 for arg in named.keys():
45 if arg not in acceptable:
46 del named[arg]
---> 47 return receiver(*arguments, **named)
C:\Python25\lib\site-packages\mptt\mptt\signals.py in pre_save(instance,
**kwarg
s)
107
108 if opts.order_insertion_by:
--> 109 right_sibling = _get_ordered_insertion_target(instance,
pare
nt)
110 if right_sibling:
111 instance.insert_at(right_sibling, 'left')
C:\Python25\lib\site-packages\mptt\mptt\signals.py in
_get_ordered_insertion_tar
get(node, parent)
49 opts = node._meta
50 order_by = opts.order_insertion_by[:]
---> 51 filters = _insertion_target_filters(node, order_by)
52 if parent:
53 filters = filters & Q(**{opts.parent_attr: parent})
C:\Python25\lib\site-packages\mptt\mptt\signals.py in
_insertion_target_filters(
node, order_insertion_by)
28 filters = []
29 for field in order_insertion_by:
---> 30 value = getattr(node, field)
31 filters.append(reduce(operator.and_, [Q(**{f: v}) for f, v
in fi
elds] +
32 [Q(**{'%s__gt' %
field: val
ue})]))
AttributeError: 'Genre' object has no attribute 'n'
Feb 5, 2008
#1
ruk...@gmail.com
Feb 6, 2008
Ok, have any of you tried making the value passed to order_insertion_by a tuple? I am pretty sure Jonathan has allowed for multiple values for that attribute. Could have been made backward compatible, but appears was not the case.
Feb 6, 2008
Here is a patch that fixes the problem. Not sure if this should even be included and mark this as a Backward Incompatible Change or not.
Feb 6, 2008
This has been on the BackwardsIncompatibleChanges page since the 24th of January, when the change was made: https://code.google.com/p/django-mptt/wiki/BackwardsIncompatibleChanges https://code.google.com/p/django-mptt/source/detail?r=100
Status:
Invalid
|