Hello i have manytomany relations (database PostgreSql 8.1.5) like
this:
class Photograph(models.Model):
        name = models.CharField(maxlength=200)
        email = models.EmailField()
        age = models.IntegerField()
        categories = models.ManyToManyField(Category)
        joined = models.DateField()
        albums = models.IntegerField()
        photos = models.IntegerField()
        county = models.ForeignKey(County)
        city = models.ForeignKey(City)
class Category(models.Model):
        name = models.CharField(maxlength=15)

I create some Categories like that:
 category = Category(name='weddings')
category.save()
and then I create a photograph and here is a problem:
In [8]: p = Photograph(name="p", email="[EMAIL PROTECTED]",albums=26,
photos=12,city=city, county=county, categories=category)
---------------------------------------------------------------------------
exceptions.TypeError                                 Traceback (most
recent call last)


C:\opt\Python24\lib\site-packages\django-0.95-py2.4.egg\django\db\models\base.py
in __init__(self, *args, **kwargs)
    123                 pass
    124         if kwargs:
--> 125             raise TypeError, "'%s' is an invalid keyword
argument for this function" % kwargs.keys()[0]
    126         for i, arg in enumerate(args):
    127             setattr(self, self._meta.fields[i].attname, arg)

TypeError: 'categories' is an invalid keyword argument for this
function


or if try to save:


Photograph.save()
In [19]: p = Photograph(name="Smith",email="[EMAIL PROTECTED]",albums=26,
photos=34, county=woj, city=miasto)

In [20]: p.save()
---------------------------------------------------------------------------
psycopg.ProgrammingError                          Traceback (most
recent call last)

I:\Prace\PRYWATNE\DJANGO_projekty\moremoments\<ipython console>

C:\opt\Python24\lib\site-packages\django-0.95-py2.4.egg\django\db\models\base.py
in save(self)
    202                 cursor.execute("INSERT INTO %s (%s) VALUES
(%s)" % \
    203                     (backend.quote_name(self._meta.db_table),
','.join(field_names),
--> 204                     ','.join(placeholders)), db_values)
    205             else:
    206                 # Create a new record with defaults for
everything.

C:\opt\Python24\lib\site-packages\django-0.95-py2.4.egg\django\db\backends\util.py
in execute(self, sql, params)
     10         start = time()
     11         try:
---> 12             return self.cursor.execute(sql, params)
     13         finally:
     14             stop = time()

ProgrammingError: ERROR:  null value in column "age" violates not-null
constraint

INSERT INTO "mm_photograph"
("name","email","age","joined","albums","photos","county_id","city_id")
VALUES ('Smith','smi
[EMAIL PROTECTED]',NW

or i try to add category:
n [21]: p.categories.add(kategoria)
--------------------------------------------------------------------------
xceptions.ValueError                                Traceback (most
recent call last)

:\Prace\PRYWATNE\DJANGO_projekty\moremoments\<ipython console>

:\opt\Python24\lib\site-packages\django-0.95-py2.4.egg\django\db\models\fields\related.py
in __get__(self, instance, in
tance_type)
   437             join_table=qn(self.field.m2m_db_table()),
   438             source_col_name=qn(self.field.m2m_column_name()),
-> 439             target_col_name=qn(self.field.m2m_reverse_name())
   440         )
   441

:\opt\Python24\lib\site-packages\django-0.95-py2.4.egg\django\db\models\fields\related.py
in __init__(self, model, core
filters, instance, symmetrical, join_table, source_col_name,
target_col_name)
   276             self._pk_val = self.instance._get_pk_val()
   277             if self._pk_val is None:
-> 278                 raise ValueError("%r instance needs to have a
primary key value before a many-to-many relationsh
p can be used." % model)
   279
   280         def get_query_set(self):

ValueError: <class 'moremoments.mm.models.Category'> instance needs to
have a primary key value before a many-to-many re
ationship can be used.


So what I'm doing wrong??
Any one help me, please


--~--~---------~--~----~------------~-------~--~----~
 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to