Thanks for your reply, Daniel.
I read the docs, but did not understand them properly. Your
explanation makes sense, but doesn't seem to be working for me, for
some reason. I followed the docs from
https://docs.djangoproject.com/en/1.3/topics/forms/modelforms/#inline-formsets
precisely, but am getting and error that my relation does not exist.
I think it may have something to do with not using a default
database. The funny thing is, I can access the related records fine
from the parent instance (i.e. user.josjeventsregistration_set). Do
you need to explicitly tell inlineformset to use a non-default DB
somehow?
In [1]: from django.forms.models import inlineformset_factory
In [2]: from classes.models import JosUsers,
JosJeventsRegistration
In [3]: RegistrationFormSet = inlineformset_factory(JosUsers,
JosJeventsRegistration)
In [4]: user = JosUsers.objects.using('mydevdb').get(pk='1234')
In [5]: fs = RegistrationFormSet(instance=user)
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (13, 0))
---------------------------------------------------------------------------
DatabaseError Traceback (most recent call
last)
/home/tony/sandbox/django/dashboard/<ipython console> in <module>()
/home/tony/sandbox/django/env/lib/python2.6/site-packages/django/forms/
models.pyc in __init__(self, data, files, instance, save_as_new,
prefix, queryset)
680 qs = queryset.filter(**{self.fk.name: self.instance})
681 super(BaseInlineFormSet, self).__init__(data, files,
prefix=prefix,
--> 682 queryset=qs)
683
684 def initial_form_count(self):
/home/tony/sandbox/django/env/lib/python2.6/site-packages/django/forms/
models.pyc in __init__(self, data, files, auto_id, prefix, queryset,
**kwargs)
413 defaults = {'data': data, 'files': files, 'auto_id':
auto_id, 'prefix': prefix}
414 defaults.update(kwargs)
--> 415 super(BaseModelFormSet, self).__init__(**defaults)
416
417 def initial_form_count(self):
/home/tony/sandbox/django/env/lib/python2.6/site-packages/django/forms/
formsets.pyc in __init__(self, data, files, auto_id, prefix, initial,
error_class)
45 self._non_form_errors = None
46 # construct the forms in the formset
---> 47 self._construct_forms()
48
49 def __unicode__(self):
/home/tony/sandbox/django/env/lib/python2.6/site-packages/django/forms/
formsets.pyc in _construct_forms(self)
105 # instantiate all the forms and put them in self.forms
106 self.forms = []
--> 107 for i in xrange(self.total_form_count()):
108 self.forms.append(self._construct_form(i))
109
/home/tony/sandbox/django/env/lib/python2.6/site-packages/django/forms/
formsets.pyc in total_form_count(self)
81 return
self.management_form.cleaned_data[TOTAL_FORM_COUNT]
82 else:
---> 83 initial_forms = self.initial_form_count()
84 total_forms = initial_forms + self.extra
85 # Allow all existing related objects/inlines to be
displayed,
/home/tony/sandbox/django/env/lib/python2.6/site-packages/django/forms/
models.pyc in initial_form_count(self)
685 if self.save_as_new:
686 return 0
--> 687 return super(BaseInlineFormSet,
self).initial_form_count()
688
689
/home/tony/sandbox/django/env/lib/python2.6/site-packages/django/forms/
models.pyc in initial_form_count(self)
418 """Returns the number of forms that are required in
this FormSet."""
419 if not (self.data or self.files):
--> 420 return len(self.get_queryset())
421 return super(BaseModelFormSet,
self).initial_form_count()
422
/home/tony/sandbox/django/env/lib/python2.6/site-packages/django/db/
models/query.pyc in __len__(self)
80 self._result_cache = list(self._iter)
81 else:
---> 82 self._result_cache = list(self.iterator())
83 elif self._iter:
84 self._result_cache.extend(self._iter)
/home/tony/sandbox/django/env/lib/python2.6/site-packages/django/db/
models/query.pyc in iterator(self)
271 model = self.model
272 compiler = self.query.get_compiler(using=db)
--> 273 for row in compiler.results_iter():
274 if fill_cache:
275 obj, _ = get_cached_row(model, row,
/home/tony/sandbox/django/env/lib/python2.6/site-packages/django/db/
models/sql/compiler.pyc in results_iter(self)
678 fields = None
679 has_aggregate_select =
bool(self.query.aggregate_select)
--> 680 for rows in self.execute_sql(MULTI):
681 for row in rows:
682 if resolve_columns:
/home/tony/sandbox/django/env/lib/python2.6/site-packages/django/db/
models/sql/compiler.pyc in execute_sql(self, result_type)
733
734 cursor = self.connection.cursor()
--> 735 cursor.execute(sql, params)
736
737 if not result_type:
/home/tony/sandbox/django/env/lib/python2.6/site-packages/django/db/
backends/util.pyc in execute(self, sql, params)
32 start = time()
33 try:
---> 34 return self.cursor.execute(sql, params)
35 finally:
36 stop = time()
/home/tony/sandbox/django/env/lib/python2.6/site-packages/django/db/
backends/postgresql_psycopg2/base.pyc in execute(self, query, args)
42 def execute(self, query, args=None):
43 try:
---> 44 return self.cursor.execute(query, args)
45 except Database.IntegrityError, e:
46 raise utils.IntegrityError,
utils.IntegrityError(*tuple(e)), sys.exc_info()[2]
DatabaseError: relation "jos_jevents_registration" does not exist
On May 31, 8:10 am, Daniel Roseman <[email protected]> wrote:
> On Tuesday, 31 May 2011 15:20:11 UTC+1, snfctech wrote:
>
> > Thanks, Jayapal.
>
> > I was hoping there was a little less java/ more django way to do this
> > by utilizing a Django ModelForm or InlindeFormSet and rendering
> > partial views.
>
> > So am I missing the point of InlineFormSets? Can these not be
> > populated with data so they can be used to edit a set of existing
> > records?
>
> > Thanks.
>
> > Tony
>
> No, you're not missing the point - that is exactly what model formsets are
> for. But you haven't read the documentation very closely: InlineFormsets are
> meant for editing only those elements that are related via ForeignKey to a
> specific object, so it is that related object that you pass to the formset
> via the `instance` parameter. The documentation shows this
> clearly:https://docs.djangoproject.com/en/1.3/topics/forms/modelforms/#inline...
>
> If you want to edit the elements of a queryset that aren't necessarily all
> related to the same object, you just use a standard ModelFormset, which does
> take a `queryset` argument - again, as shown in the
> docs:https://docs.djangoproject.com/en/1.3/topics/forms/modelforms/#using-...
> --
> DR.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
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.