How to solve this ?

3 views
Skip to first unread message

PythonistL

unread,
Mar 14, 2006, 3:07:17 AM3/14/06
to Django users
If I add some data to one table, via a form, will be this data shown in
another form that uses a different table?
To explain in detail:

I have this model
###################
..
..

class Category(meta.Model):
CategoryName=meta.CharField(maxlength=100,unique=True)
CategoryDescription=meta.CharField(maxlength=200,blank=True)
Priority=meta.IntegerField(maxlength=6,blank=True,null=True)
Subcategory= meta.IntegerField(maxlength=6,blank=True,null=True)
Date=meta.DateTimeField(auto_now_add=True)
def __repr__(self):
return self.CategoryName
class META:
admin = meta.Admin(
search_fields = ['CategoryName'],
)

class Product(meta.Model):
PictureNo=meta.CharField(maxlength=10,blank=True)
Name=meta.CharField(maxlength=100,blank=True)
Description=meta.TextField(blank=True)
Price=meta.IntegerField(maxlength=6,blank=True,null=True)
Vat=meta.IntegerField(maxlength=4,blank=True,null=True)

TypeofPromotiont=meta.CharField(maxlength=50,choices=(('Normal','Normal'),('New','New'),('Action','Action'),('Discount','Discount')))
Date=meta.DateTimeField(auto_now_add=True)
productkey=meta.ForeignKey(Category)
def __repr__(self):
return self.Name
class META:
admin = meta.Admin(
search_fields = ['Name'],
)
####################
When I add a new Category I need to make a possible for a user to be
able to choose that category for the Product that he is being
inserted.Is that possible in Django?

Thank you for your reply
Regards,
L

Kenneth Gonsalves

unread,
Mar 14, 2006, 3:56:37 AM3/14/06
to django...@googlegroups.com
On Tuesday 14 Mar 2006 1:37 pm, PythonistL wrote:
> When I add a new Category I need to make a possible for a user to
> be able to choose that category for the Product that he is being
> inserted.Is that possible in Django?

promotion should have a foreign key to product table, and product
table should have a foreign key to category table - otherwise it
doesnt make sense

--
regards
kg

http://www.livejournal.com/users/lawgon
tally ho! http://avsap.org.in
ಇಂಡ್ಲಿನಕ್ಸ வாழ்க!

PythonistL

unread,
Mar 14, 2006, 5:12:55 AM3/14/06
to Django users
Kenneth,thank you for your reply.
The whole model looks like this
#########################
from django.core import meta

class User(meta.Model):
Login=meta.CharField(maxlength=50,unique=True)
Password=meta.CharField(maxlength=30,blank=True)
Email=meta.EmailField(_('e-mail address'),blank=True)
RealName= meta.CharField(maxlength=70,blank=True)
Company= meta.CharField(maxlength=70,blank=True)
Address= meta.CharField( maxlength=200,blank=True)
Zip= meta.CharField(maxlength=5,blank=True)
DateOfJoined=meta.DateTimeField(auto_now_add=True)
Phone= meta.CharField( maxlength=25,blank=True)
Fax= meta.CharField(maxlength=25,blank=True)
Notes=meta.TextField(blank=True)
PaidUser=meta.IntegerField(blank=True,null=True)#0 not paid
def __repr__(self):
return self.Login

class META:
admin = meta.Admin(

search_fields = ['Login'],
)

class Category(meta.Model):
CategoryName=meta.CharField(maxlength=100,unique=True)
CategoryDescription=meta.CharField(maxlength=200,blank=True)
Priority=meta.IntegerField(maxlength=6,blank=True,null=True)
Subcategory= meta.IntegerField(maxlength=6,blank=True,null=True)
Date=meta.DateTimeField(auto_now_add=True)

categorykey=meta.ForeignKey(User)


def __repr__(self):
return self.CategoryName
class META:
admin = meta.Admin(
search_fields = ['CategoryName'],
)

class Product(meta.Model):
PictureNo=meta.CharField(maxlength=10,blank=True)
Name=meta.CharField(maxlength=100,blank=True)
Description=meta.TextField(blank=True)
Price=meta.IntegerField(maxlength=6,blank=True,null=True)
Vat=meta.IntegerField(maxlength=4,blank=True,null=True)

TypeofPromotiont=meta.CharField(maxlength=50,choices=(('Normal','Normal'),('New','New'),('Action','Action'),('Discount','Discount')))
Date=meta.DateTimeField(auto_now_add=True)
productkey=meta.ForeignKey(Category)
def __repr__(self):
return self.Name
class META:
admin = meta.Admin(
search_fields = ['Name'],
)

class OrderList(meta.Model):#all orders that a user placed
ProductNo=meta.CharField(maxlength=10)
Description=meta.TextField(blank=True)
Date=meta.DateTimeField(auto_now_add=True)
orderlistkey=meta.ForeignKey(User)
def __repr__(self):
return self.ProductNo


class META:
admin = meta.Admin(
search_fields = ['Name'],
)

class Order(meta.Model):

Name=meta.CharField(maxlength=100,blank=True)
Description=meta.TextField(blank=True)
Price=meta.IntegerField(maxlength=6,blank=True,null=True)
Vat=meta.IntegerField(maxlength=4,blank=True,null=True)
Pieces=meta.IntegerField(maxlength=6,blank=True,null=True)
Date=meta.DateTimeField(auto_now_add=True)
orderkey=meta.ForeignKey(User)


def __repr__(self):
return self.Name
class META:
admin = meta.Admin(
search_fields = ['Name'],
)
##########

Does this make already sense?
Thank you for the reply
Regrads,
L

Kenneth Gonsalves

unread,
Mar 14, 2006, 5:26:40 AM3/14/06
to django...@googlegroups.com
On Tuesday 14 Mar 2006 3:42 pm, PythonistL wrote:
> Does this make already sense?
> Thank you for the reply

yes it makes sense, and my previous post was wrong - due to the
break up of lines in my mail client i thought there was an extra
table called promotionlist - which confused me

Kenneth Gonsalves

unread,
Mar 14, 2006, 5:28:02 AM3/14/06
to django...@googlegroups.com
On Tuesday 14 Mar 2006 1:37 pm, PythonistL wrote:
> When I add a new Category I need to make a possible for a user to
> be able to choose that category for the Product that he is being
> inserted.Is that possible in Django?

that automatically happens in the admin doesnt it?

PythonistL

unread,
Mar 14, 2006, 6:47:01 AM3/14/06
to Django users
Kenneth,Thank you for your reply.
Yes,that automatically happens in the admin but I need to make my own
application so that when a user adds a new Category he is able to

choose that category for the Product that he is being
inserted.And I do not know how to add the Category list into a product
form. Any idea?
Can you please help?
Thank you
L.

Kenneth Gonsalves

unread,
Mar 14, 2006, 8:27:37 AM3/14/06
to django...@googlegroups.com
On Tuesday 14 Mar 2006 5:17 pm, PythonistL wrote:
> Yes,that automatically happens in the admin but I need to make my
> own application so that when a user adds a new Category he is
> able to choose that category for the Product that he is being
> inserted.And I do not know how to add the Category list into a
> product form. Any idea?

check this out - it will do it automagically in your view also
http://code.djangoproject.com/wiki/NewAdminChanges
(dont forget to use flatten_data())

PythonistL

unread,
Mar 14, 2006, 12:04:28 PM3/14/06
to Django users
Kenneth,Thank you for your reply.I checked the link but it describes
inline editing.It was my fault that I did not explain properly.I am
sorry about that.
All that I want is to have in a form input fields (data) from a
different tables that are linked via a ForeignKey.In the example above
Product table is linked with Category table via a ForeignKey
productkey, see productkey=meta.ForeignKey(Category).
Is that possible?

Thank you for the reply
Regards,
L. ¶

Kenneth Gonsalves

unread,
Mar 14, 2006, 11:38:59 PM3/14/06
to django...@googlegroups.com
On Tuesday 14 Mar 2006 10:34 pm, PythonistL wrote:
> Kenneth,Thank you for your reply.I checked the link but it
> describes inline editing.It was my fault that I did not explain
> properly.I am sorry about that.

it does not describe inline editing - you will get inline editing if
you have set that in your model - otherwise you will get a drop
down list of your foreign key field with a '+' sign for adding new
ones

> All that I want is to have in a form input fields (data) from a
> different tables that are linked via a ForeignKey.In the example
> above Product table is linked with Category table via a
> ForeignKey productkey, see  productkey=meta.ForeignKey(Category).
> Is that possible?

yes - see above

Reply all
Reply to author
Forward
0 new messages