I have this model:

from django.db import models

class Subjekt(models.Model):
    """
    >>> osoba = Osoba(meno = "Ludmila", priezvisko = "Safarova")
    >>> osoba
    <Osoba: Safarova Ludmila>
    >>> subjekt = Subjekt(nazov = "Zaba s.r.o.", osoba = osoba)
    >>> subjekt
    <Subjekt: Zaba s.r.o. - Safarova Ludmila>
    >>> subjekt.osoba.save()
    >>> subjekt.osoba
    <Osoba: Safarova Ludmila>
    >>> subjekt.osoba.id
    1
    """
    class Meta:
        verbose_name = "subjekt"
        verbose_name_plural = "subjekty"
    nazov = models.CharField(
        unique = True,
        max_length = 60,
        verbose_name = "nazov",
    )
    osoba = models.OneToOneField(
        'Osoba',
        verbose_name = "osoba",
        related_name = 'subjekt'
    )
    def __unicode__(self):
        return "%s - %s" % (self.nazov, self.osoba)

class Osoba(models.Model):
    """
    >>> Osoba(meno = "Ludmila", priezvisko = "Safarova")
    <Osoba: Safarova Ludmila>
    """
    class Meta:
        verbose_name = "osoba"
        verbose_name_plural = "osoby"
    meno = models.CharField(
        max_length = 60,
        verbose_name = "meno",
    )
    priezvisko = models.CharField(
        max_length = 60,
        verbose_name = "priezvisko",
    )
    def __unicode__(self):
        return "%s %s" % (self.priezvisko, self.meno)

So far - the manage.py test with SQLite is succesful - the result is
OK. But after I append this line to the test:
    >>> subjekt.save()

so the whole test is:
class Subjekt(models.Model):
    """
    >>> osoba = Osoba(meno = "Ludmila", priezvisko = "Safarova")
    >>> osoba
    <Osoba: Safarova Ludmila>
    >>> subjekt = Subjekt(nazov = "Zaba s.r.o.", osoba = osoba)
    >>> subjekt
    <Subjekt: Zaba s.r.o. - Safarova Ludmila>
    >>> subjekt.osoba.save()
    >>> subjekt.osoba
    <Osoba: Safarova Ludmila>
    >>> subjekt.osoba.id
    1
    >>> subjekt.save()
    """
I got this error message:

FAIL: Doctest: konres.subjekty.models.Subjekt
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Library/Python/2.5/site-packages/django/test/_doctest.py",
line 2180, in runTest
    raise self.failureException(self.format_failure(new.getvalue
()).encode('UTF-8'))
AssertionError: Failed doctest test for konres.subjekty.models.Subjekt
  File "/Users/iM1/Sites/konres/../konres/subjekty/models.py", line 3,
in Subjekt

----------------------------------------------------------------------
File "/Users/iM1/Sites/konres/../konres/subjekty/models.py", line 16,
in konres.subjekty.models.Subjekt
Failed example:
    subjekt.save()
Exception raised:
    Traceback (most recent call last):
      File "/Library/Python/2.5/site-packages/django/test/
_doctest.py", line 1267, in __run
        compileflags, 1) in test.globs
      File "<doctest konres.subjekty.models.Subjekt[7]>", line 1, in
<module>
        subjekt.save()
      File "/Library/Python/2.5/site-packages/django/db/models/
base.py", line 410, in save
        self.save_base(force_insert=force_insert,
force_update=force_update)
      File "/Library/Python/2.5/site-packages/django/db/models/
base.py", line 495, in save_base
        result = manager._insert(values, return_id=update_pk)
      File "/Library/Python/2.5/site-packages/django/db/models/
manager.py", line 177, in _insert
        return insert_query(self.model, values, **kwargs)
      File "/Library/Python/2.5/site-packages/django/db/models/
query.py", line 1087, in insert_query
        return query.execute_sql(return_id)
      File "/Library/Python/2.5/site-packages/django/db/models/sql/
subqueries.py", line 320, in execute_sql
        cursor = super(InsertQuery, self).execute_sql(None)
      File "/Library/Python/2.5/site-packages/django/db/models/sql/
query.py", line 2369, in execute_sql
        cursor.execute(sql, params)
      File "/Library/Python/2.5/site-packages/django/db/backends/
sqlite3/base.py", line 193, in execute
        return Database.Cursor.execute(self, query, params)
    IntegrityError: subjekty_subjekt.osoba_id may not be NULL

And I don't know why. The model instance osoba is saved and has an id
1. The ugly doctest lies!

--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to