You will need to make an admin.py and follow these directions
class FormAdmin(admin.ModelAdmin):
prepopulated_fields = {"slug": ("title",)}
slug can be what ever field you want to populate and title is where you are populating from, as far as I know you can only populate from within the same area.
prepopulated_fields = {"slug": ("title",)}
slug can be what ever field you want to populate and title is where you are populating from, as far as I know you can only populate from within the same area.
then you need to register form and formadmin
admin.site.register(form, formadmin)
On Sat, Nov 27, 2010 at 8:11 AM, djangobeginner <margarita.ladera@jmango.net> wrote:
Hi,
Im a beginner here, would just like to ask how to pass and populate
model values (from database) into a created form, I have the following
codes
1. I already have a webpage list of all the values in a table form
2. If I click on any of the row with primary key id (example: clicking
edit link), it should redirect me to a created form (in forms.py) with
all the values populated based on the primary key id from the web
list.
How do I possibly do #2?
Please help. thanks.
given the following:
---------------------------------------
models.py:
from django.db import models
import datetime
SHORT_DATE_FORMAT = "%d - %b - %y"
DATE_FORMAT= "%Y-%m-%d"
TIME_FORMAT= "%H:%M"
class Job(models.Model):
job_id = models.AutoField(primary_key=True)
job_title = models.CharField(max_length=50, verbose_name =
"Title")
job_desc = models.CharField(max_length=500, verbose_name =
"Description")
active_datetime_fr = models.DateTimeField('time')
active_datetime_to = models.DateTimeField('time')
-----------------------------------------
views.py
def object_list(request, model):
obj_list = model.objects.all()
template_name = '/job_list.html'
t = loader.get_template(template_name)
c = RequestContext(request, {"object_list": obj_list})
return HttpResponse(t.render(c))
-----------------------------------------
forms.py:
from django import forms
from django.db.models.fields import AutoField
from datetime import date, datetime
import psycopg2
class JobAddForm(forms.Form):
#job_id = forms.IntegerField()
job_title = forms.CharField(label='Title', initial='',
required=True)
job_desc = forms.CharField(label='Description', initial='',
required=False)
date_fr = forms.DateField(required=True, label ="Active From
Date")
date_to = forms.DateField(required=True, label ="Active To Date")
time_to = forms.TimeField(required=True, label ="Active From
Time")
time_fr = forms.TimeField(required=True, label ="Active To Time")
-------------------------------------------------
--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment