Custom Model Fields

2010-05-09 Thread Nick Taylor
Hi all,

I want to create my own "field" type for a model, this essentially
will be a relationship to another model via a generic link model
(using GenericForeignKey etc).

As en example I basically want to do the following in models.py:

class Pizza(models.Model):
   toppings = IngredientsField()

Which can then be reused in another app sandwiches/models.py as:

class Sandwich(models.Model)
   filling = IngredientsField()

Where I use a IngredientsField() field type which then controls the
links as a separate set of models Ingredients and IngredientItems.

Now I have created in fields.py:

class IngredientsField(CharField):
def __init__(self, *args, **kwargs):
..

However I get an "Unknown column 'pizza_pizza.toppings' in 'field
list'" error - BUT I don't want to add it as a column in toppings as I
want it to be linked via the link table/model IngredientItems.
Eventually what I want to achieve is while using the admin system for
certain models that you manage there will be a text box where you can
enter ingredients into a TextField in the admin comma delimited
"Cheese, Ham" and then the model take care of the rest.

Hopefully I'm pretty close, any ideas anyone?

Thanks in advance,

Nick

-- 
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.



Additional Text Form Field within a Models Admin Screen

2010-05-08 Thread Nick Taylor
Hi all,

I'm pretty new to Django so bare with me if this is a simple question.

Basically, I have an Article model which is simply title, body, status
etc. Now, I want to add an additional TextBox to the admin for the
model, but I don't want to add it as part of the Article model, as I
don't want to store it directly into the database as a string.

The TextBox will take an input, lets say "1, 2, 3, 4" I then want to
programmatically split this by the comma and add each item (1, 2, 3,
4) as a separate record which is a pre-existing model.

Any advice here would be greatly appreciated!

Thanks a lot,

Nick

-- 
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.