> When I tried to run the command (python manage.py syncdb), the table cannot
> be created. The SQL command are just
>
> Begin;
> Commit;

Your form definitions have nothing to do with the database.  They are
completely separate things.  There are a few helpers that combine the
two for convenience, but they are independent of each other normally.

In answer to your question, I'll tell you how I did something
similar.

Make a basic model with a 'pickled' textfield.  The model fields
represent all the static/searchable fields.  Any fields that will
always be there should be a model field. The pickled field contains a
serialized python dict with all of the changeable fields.  The dict is
something like:

{'fieldname': value1, 'fieldname': value2} where fieldname is a key
into a FieldDef model/table that has meta information about that field
type like formfield, attrs, validation information,etc. (if you have a
smaller, static set it wouldn't even need a model, just a lookup dict)

You can build the form 'on the fly' by using the information in the
FieldDef model something like this:

class GeneratedBaseForm(forms.BaseForm):
    def save(instance,*args,**kwargs):
         ... do something here to look at self.fieldmeta/instance/
clean_data and save accordingly

def make_form(fieldmeta):
    base_fields={}
    for f in fieldmeta:
        base_fields[f.name] = getattr(forms,f.formfield)()
    return type('GeneratedForm',(GeneratedBaseForm,),{''fieldmeta':
fieldmeta,base_fields': base_fields })

fieldmeta =
FieldDef.objects.filter(name__in=['fieldname1','fieldname2'])
Form = make_form(fieldmeta)
form=Form()

If you write the save method on the baseform carefully, you can have
it look at the instance model._meta and update the real model fields,
then pickle the rest of clean_data and store it in the pickle field.
Same with __init__.

I also tried using a FieldDef model, Base model, and a Field model:

class MyModel(models.Model):
   ....
class FieldDef(models.Model):
    formfield=models.CharField()
    ... bunch of meta fields

class Field(models.Model):
    fielddef=models.ForeignKey(FieldDef)
    instance=models.ForeignKey(MyModel)

instance=MyModel.objects.get(pk=1)
fields=instance.field_set.all()

Then just step through fields, checking field.fielddef.formfield and
other meta information and building the form like above.  It worked
better, because all fields were searchable... but when I got to
several million field rows the slow performance started to show.
Using the serialized fields was much, much faster for what I  was
doing..


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to