Kenny Meyer (knny.m...@gmail.com) wrote:
> Hello,
> 
> I have two models, 1) FlashCard and 2) Practice, and I have a generic relation
> in the FlashCard model pointing to the Practice model using the contenttypes
> framework.
> The Practice model tracks information like how many times something was
> practiced, and calculates an `easy factor'.
> Each time I save a FlashCard I want at the same time to create Practice
> object for the flashcard, automatically.
> 
> 
> class Practice(models.Model):
>     content_type = models.ForeignKey(ContentType)
>     object_id = models.PositiveIntegerField()
>     item = generic.GenericForeignKey('content_type', 'object_id')
> 
>     user = models.ForeignKey(User)
> 
> 
> class FlashCard(models.Model):
>     """
>     A basic Flashcard.
> 
>     Has a front and a back view.
>     """
>     front = models.TextField(
>                     max_length = 255,
>                     verbose_name = "Front")
>     back = models.TextField(
>                     max_length = 255,
>                     verbose_name = "Back")
>     user = models.ForeignKey(User)
>     practice = generic.GenericRelation(Practice)
> 
> 
> I read the contenttypes documentation, and as far as I understand to create a
> related Practice object for a flashcard instance I should do the following:
> 
> >>> user = User.objects.get(username="kenny")
>     # Create a sample flashcard
> >>> flashcard = ("bla", "bla", user)
>     # ...and create a Practice object for it
> >>> new_practice = Practice(item=flashcard)
>     # then I try to save it, but that fails with a large backtrace
> >>> new_practice.save()
> [snip]
> 
> Here the actual backtrace: http://dpaste.com/hold/272617/

Ok, this is my error. Creating a flashcard was actually this:

   FlashCard(front="front side", back="back side", user)

then it worked, and so I could also create a Practice object.

> Well, but this is not the reason I opened this thread. Still I want to create
> Practice object for my FlashCard object.
> 
> I started a research on Google, but I really haven't found anything really
> helping me to do that.
> 
> Can you guys give me a helping hand on this with your expertise, please?
> 
> Additional information about my environment:
>   - Django 1.2.3
>   - PostgreSQL 8.4.5
> 
> Cheers,
> Kenny
> 
> -- 
> - Kenny Meyer <knny.m...@gmail.com>
> To understand recursion, we must first understand recursion.
> --

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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