Re: Generic foreignKey model: Category

2009-02-16 Thread Muslu Yüksektepe
hi guys; i wrote this codes. but how can i use in template like first choose company category product On 12 Şubat, 19:13, danfreak wrote: > Right, I created my Genric Category model using : > > - > from django.db import models > from django.co

Re: Generic foreignKey model: Category

2009-02-12 Thread danfreak
Right, I created my Genric Category model using : - from django.db import models from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic from django import forms

Re: Generic foreignKey model: Category

2009-02-11 Thread danfreak
Yep, I'm a bginner with Django, but translating it into CakePHP (based on Rails) I would like to define a kind of relation where, given the: - Foreign key of let's say the News.id - the Foreign_model_name (i.e News) I get the News.category of a specific item While just retriving the News Categ

Re: Generic foreignKey model: Category

2009-02-11 Thread Jake Elliott
if i follow your question - you'd want a ForeignKey in CategoryItem to your Category model, so you can add both your News object and Product object to the same category through CategoryItem. then you'll be able to iterate through all of the items in a categoroy with something like `mycategory.cat

Re: Generic foreignKey model: Category

2009-02-11 Thread Jake Elliott
hi dan - a little further down on the contenttypes doc page you link to there is documentation on the generic foreign key mechanism bundled with the contenttypes app: http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#id1 pretty similar to what you describe ;) On Wed, Feb 11, 2009 a

Re: Generic foreignKey model: Category

2009-02-11 Thread danfreak
Cheers Jake, given the code: -- from django.db import models from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic class CategoryItem(models.Model): name = models.CharField(max_length=200) content_type = models.ForeignKey(C

Generic foreignKey model: Category

2009-02-11 Thread danfreak
Hey guys, I was wondering how to create a let's call it "GenericCategory" model. Given that News, Products, etc, often belongs to a Category, why have tons of tables (news_categories, products_categories) etc The "GenericCategory" model table structure should be like: - id - foreign_model_name