inserting data in a DateTimeField() in Django by using datetime-local - django

Please, I am creating a to-do list app as my first django project.
My form is not valid because I am trying to insert DateTimeField in django using datetime-local.
I did research, I discovered I need to do a custom model so I parse the datetime-local field.
Pls guide me on how to create a custom model field.

Related

django arrayfield saving a array item containing comma

I have a django model that has a postgres array field
ArrayField(blank=True, default=list, base_field=CICharField(max_length=200, blank=True))
There is also a corresponding admin page for this model where I can update field this in the regular case, but If for example I want to save the field as ['foo,bar', 'baz'] this is not possible since django seems to be splitting always by comma. I tried saving with "foo,bar",baz thinking csv rules but that didn't work out either. Is there any workaround to achive this in django admin ?

Can there be a general way of extracting 'cleaned_data' from a django form after post? Such that this can be used for any django form

I was wondering if we can create a general method that would accept a form instance after POST and extract all fields into a dict with keys same as the field names from the django form.

how to remove data that already in use in onetoonefield django admin form

in onetoonefield django admin form displays all existing data. How to display only the data that has not been in use?
or how to remove data that already in used?
sorry, my english is bad ..

How can I save a Django field (as in the field object) to the database?

I'm trying to implement a reusable form that users can download the source code in HTML which was site generated for them by the site. They can also create their forms using an interface where they get to choose the fields they want and rank them so the highest would appear first in the downloadable form.
They can then use the form in their sites to gather customer data and when the form gets submitted, the action parameter points back to our site so we can store the information on our servers.
Now, my question is, how can I save a Django Field object in my database? This is so I can store the forms that the users created, especially the Fields that they chose.
I need to store the Fields so that I can create a generic Django ModelForm and the users can save the Fields of that ModelForm in their downloadable forms. So when they submit back the information to us I can feed the information straight to the ModelForm (since the Fields would be recognizable) and do some further validation.
Also I have to add some basic javascript validations (like validation.js) for each field (must be present when the user downloads the form), and I know it will be easier if I can save the Fields themselves.
You could pickle the Field object:
import cPickle
field = forms.CharField()
dump = cPickle.dumps(field) # serializes field as an ASCII string
my_model.stored_field = dump
To unpickle:
field = cPickle.loads(my_model.stored_field)
http://docs.python.org/library/pickle.html

Django FormWizard prefill on edit

I'm using a FormWizard to edit objects and I want to be able to prefill the fields from database when the edit page is loaded.
For example if my URL is 'category_edit_wizard/5', the field 'title' should have the value of the category with the ID 5 when the page is loaded.
Any way to do that?
Thank you
If you're using django-formwizard or the new formwizard implementation introduced in Django 1.4 you can use ModelForm's as a step form and pass an instance_dict when creating the WizardView instance.
instance_dict works the same way initial_dict works - see
https://django-formtools.readthedocs.io/en/latest/wizard.html#formtools.wizard.views.WizardView.initial_dict
If you're using the old formwizard implementation from Django 1.3 and lower, you can pass initial as described here: https://django-formtools.readthedocs.io/en/latest/wizard.html#providing-initial-data-for-the-forms