Hello!

I'm new to web development and my trying web2py because of DRY and,
most importantly, Python.

I created a model, however I can't insert records in the admin
interface because of a constraints-error I don't understand.

When trying to insert a record here:
http://127.0.0.1:8000/task/appadmin/insert/db/task

I get the Error Snapshot:
<class 'pyodbc.IntegrityError'>
    (
        ('23000',
        '[23000] [Microsoft][ODBC SQL Server Driver][SQL Server]
        The INSERT statement conflicted with the FOREIGN KEY
constraint "task_id_person_assigned__constraint".
        The conflict occurred in database "taskdb", table
"dbo.person", column \'id\'. (547) (SQLExecDirectW);
        [01000] [Microsoft][ODBC SQL Server Driver][SQL Server]The
statement has been terminated. (3621)'
        )
    )


What I really want is to have dropdown fields in [task] for all three
person-fields, where only persons from the list can be chosen or no
one (a task could be created without yet assigning it to anybody).

Additionally I'd like to have a field in [task] where I can choose 0
to n categories.

Thank you very much!

Lucas.


Model:

<code>
#    Table Definitions

db.define_table("person",
    Field("initials", "string", length=16, notnull=True, default=None,
unique=True),
    Field("name_last", "string", length=128, notnull=True,
default=None),
    Field("name_first", "string", length=128, notnull=False,
default=None)
    )

db.define_table("category",
    Field("name", "string", length=128, notnull=True, default=None,
unique=True)
    )

db.define_table("task",
    Field("title", "string", length=256, notnull=True, default=None),
    Field("description", "text"),
    Field("id_person_assigned", db.person, ondelete='NO ACTION'),
    Field("id_person_responsible", db.person, ondelete='NO ACTION'),
    Field("id_person_released", db.person, ondelete='NO ACTION'),
    Field("date_due", "datetime"),
    Field("date_nextcheck", "datetime")
    )

db.define_table("task_category",
    SQLField("id_category", db.category),
    SQLField("id_task", db.task)
    )

#    Table Relations
#    (remove fields you don't need from requires)

db.task.id_person_assigned.requires       = IS_IN_DB( db,
'person.initials', '%(initials)s  |  %(name_first)s %(name_last)s')
db.task.id_person_responsible.requires    = IS_IN_DB( db,
'person.initials', '%(initials)s  |  %(name_first)s %(name_last)s')
db.task.id_person_released.requires       = IS_IN_DB( db,
'person.initials', '%(initials)s  |  %(name_first)s %(name_last)s')

task_category = db(
    (db.category.id == db.task_category.id_category) | (db.task.id ==
db.task_category.id_task)
    )
</code>

Reply via email to