Re: wondering how to do something similar to save_model for inline.

2009-01-07 Thread Timboy

Good call on the ModelAdmin spot. (user contacted me by email to see
if I had a solution yet.)

I got the formset.save() from here:
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-save-method
saying: "If your formset contains a ManyToManyField, you'll also need
to call formset.save_m2m() to ensure the many-to-many relationships
are saved properly."

Works now just had it in the wrong spot. thx!

On Jan 6, 9:23 pm, "Karen Tracey"  wrote:
> On Tue, Jan 6, 2009 at 10:10 PM, Timboy  wrote:
>
> > Still no solution to this. It has been confirmed by another user. Is
> > it a bug?
>
> (Where was it confirmed by another user?  I don't see that.)
>
> The doc list "save_formset" under "ModelAdmin methods" yet you seem to have
> added it to your inline admin class.  I also don't see any indication in the
> traceback you posted that your custom method is being called, which leads me
> to think where you have put it is not where it needs to be in order for it
> to be called.
>
> (Also you changed formset.save_m2m() from the example in the docs to
> formset.save().  I doubt that this change is correct.)
>
> Karen
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: wondering how to do something similar to save_model for inline.

2009-01-06 Thread Karen Tracey
On Tue, Jan 6, 2009 at 10:10 PM, Timboy  wrote:

>
> Still no solution to this. It has been confirmed by another user. Is
> it a bug?
>

(Where was it confirmed by another user?  I don't see that.)

The doc list "save_formset" under "ModelAdmin methods" yet you seem to have
added it to your inline admin class.  I also don't see any indication in the
traceback you posted that your custom method is being called, which leads me
to think where you have put it is not where it needs to be in order for it
to be called.

(Also you changed formset.save_m2m() from the example in the docs to
formset.save().  I doubt that this change is correct.)

Karen

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: wondering how to do something similar to save_model for inline.

2009-01-06 Thread Timboy

Still no solution to this. It has been confirmed by another user. Is
it a bug?

On Dec 29 2008, 2:33 pm, Timboy  wrote:
> DB is sqlite3. Deleted DB file syncd and still same traceback.
> here is proper traceback paste:http://dpaste.com/103517/
>
> On Dec 28, 9:10 pm, Praveen  wrote:
>
> > This is your database error..
>
> > On Dec 28, 8:32 am, Timboy  wrote:
>
> > > Great link. I was really excited to try it.
>
> > > Here is my new inline:
> > > class rentalInline(admin.TabularInline):
> > >     model= Rent
> > >     extra = 3
> > >     raw_id_fields = ('movie',)
> > >     exclude = ['rented_by']
>
> > >     def save_formset(self, request, form, formset, change):
> > >         instances = formset.save(commit=False)
> > >         for instance in instances:
> > >             instance.rented_by = request.user
> > >             instance.save()
> > >         formset.save()
>
> > > I am still getting the same issue:
> > > Traceback:
> > > File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py"
> > > in get_response
> > >   86.                 response = callback(request, *callback_args,
> > > **callback_kwargs)
> > > File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py"
> > > in root
> > >   157.                 return self.model_page(request, *url.split('/',
> > > 2))
> > > File "/usr/lib/python2.5/site-packages/django/views/decorators/
> > > cache.py" in _wrapped_view_func
> > >   44.         response = view_func(request, *args, **kwargs)
> > > File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py"
> > > in model_page
> > >   176.         return admin_obj(request, rest_of_url)
> > > File "/usr/lib/python2.5/site-packages/django/contrib/admin/
> > > options.py" in __call__
> > >   197.             return self.change_view(request, unquote(url))
> > > File "/usr/lib/python2.5/site-packages/django/db/transaction.py" in
> > > _commit_on_success
> > >   238.                 res = func(*args, **kw)
> > > File "/usr/lib/python2.5/site-packages/django/contrib/admin/
> > > options.py" in change_view
> > >   583.                     self.save_formset(request, form, formset,
> > > change=True)
> > > File "/usr/lib/python2.5/site-packages/django/contrib/admin/
> > > options.py" in save_formset
> > >   382.         formset.save()
> > > File "/usr/lib/python2.5/site-packages/django/forms/models.py" in save
> > >   372.         return self.save_existing_objects(commit) +
> > > self.save_new_objects(commit)
> > > File "/usr/lib/python2.5/site-packages/django/forms/models.py" in
> > > save_new_objects
> > >   407.             self.new_objects.append(self.save_new(form,
> > > commit=commit))
> > > File "/usr/lib/python2.5/site-packages/django/forms/models.py" in
> > > save_new
> > >   473.         return save_instance(form, new_obj, exclude=
> > > [self._pk_field.name], commit=commit)
> > > File "/usr/lib/python2.5/site-packages/django/forms/models.py" in
> > > save_instance
> > >   59.         instance.save()
> > > File "/home/richard/work/svn/moviedb/../moviedb/store/models.py" in
> > > save
> > >   91.         super(Rent, self).save(**kwargs)
> > > File "/usr/lib/python2.5/site-packages/django/db/models/base.py" in
> > > save
> > >   307.         self.save_base(force_insert=force_insert,
> > > force_update=force_update)
> > > File "/usr/lib/python2.5/site-packages/django/db/models/base.py" in
> > > save_base
> > >   379.                 result = manager._insert(values,
> > > return_id=update_pk)
> > > File "/usr/lib/python2.5/site-packages/django/db/models/manager.py" in
> > > _insert
> > >   138.         return insert_query(self.model, values, **kwargs)
> > > File "/usr/lib/python2.5/site-packages/django/db/models/query.py" in
> > > insert_query
> > >   888.     return query.execute_sql(return_id)
> > > File "/usr/lib/python2.5/site-packages/django/db/models/sql/
> > > subqueries.py" in execute_sql
> > >   308.         cursor = super(InsertQuery, self).execute_sql(None)
> > > File "/usr/lib/python2.5/site-packages/django/db/models/sql/query.py"
> > > in execute_sql
> > >   1700.         cursor.execute(sql, params)
> > > File "/usr/lib/python2.5/site-packages/django/db/backends/util.py" in
> > > execute
> > >   19.             return self.cursor.execute(sql, params)
>
> > > Exception Type: IntegrityError at /admin/store/renter/4/
> > > Exception Value: null value in column "rented_by_id" violates not-null
> > > constraint
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: wondering how to do something similar to save_model for inline.

2008-12-29 Thread Timboy

DB is sqlite3. Deleted DB file syncd and still same traceback.
here is proper traceback paste: http://dpaste.com/103517/

On Dec 28, 9:10 pm, Praveen  wrote:
> This is your database error..
>
> On Dec 28, 8:32 am, Timboy  wrote:
>
> > Great link. I was really excited to try it.
>
> > Here is my new inline:
> > class rentalInline(admin.TabularInline):
> >     model= Rent
> >     extra = 3
> >     raw_id_fields = ('movie',)
> >     exclude = ['rented_by']
>
> >     def save_formset(self, request, form, formset, change):
> >         instances = formset.save(commit=False)
> >         for instance in instances:
> >             instance.rented_by = request.user
> >             instance.save()
> >         formset.save()
>
> > I am still getting the same issue:
> > Traceback:
> > File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py"
> > in get_response
> >   86.                 response = callback(request, *callback_args,
> > **callback_kwargs)
> > File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py"
> > in root
> >   157.                 return self.model_page(request, *url.split('/',
> > 2))
> > File "/usr/lib/python2.5/site-packages/django/views/decorators/
> > cache.py" in _wrapped_view_func
> >   44.         response = view_func(request, *args, **kwargs)
> > File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py"
> > in model_page
> >   176.         return admin_obj(request, rest_of_url)
> > File "/usr/lib/python2.5/site-packages/django/contrib/admin/
> > options.py" in __call__
> >   197.             return self.change_view(request, unquote(url))
> > File "/usr/lib/python2.5/site-packages/django/db/transaction.py" in
> > _commit_on_success
> >   238.                 res = func(*args, **kw)
> > File "/usr/lib/python2.5/site-packages/django/contrib/admin/
> > options.py" in change_view
> >   583.                     self.save_formset(request, form, formset,
> > change=True)
> > File "/usr/lib/python2.5/site-packages/django/contrib/admin/
> > options.py" in save_formset
> >   382.         formset.save()
> > File "/usr/lib/python2.5/site-packages/django/forms/models.py" in save
> >   372.         return self.save_existing_objects(commit) +
> > self.save_new_objects(commit)
> > File "/usr/lib/python2.5/site-packages/django/forms/models.py" in
> > save_new_objects
> >   407.             self.new_objects.append(self.save_new(form,
> > commit=commit))
> > File "/usr/lib/python2.5/site-packages/django/forms/models.py" in
> > save_new
> >   473.         return save_instance(form, new_obj, exclude=
> > [self._pk_field.name], commit=commit)
> > File "/usr/lib/python2.5/site-packages/django/forms/models.py" in
> > save_instance
> >   59.         instance.save()
> > File "/home/richard/work/svn/moviedb/../moviedb/store/models.py" in
> > save
> >   91.         super(Rent, self).save(**kwargs)
> > File "/usr/lib/python2.5/site-packages/django/db/models/base.py" in
> > save
> >   307.         self.save_base(force_insert=force_insert,
> > force_update=force_update)
> > File "/usr/lib/python2.5/site-packages/django/db/models/base.py" in
> > save_base
> >   379.                 result = manager._insert(values,
> > return_id=update_pk)
> > File "/usr/lib/python2.5/site-packages/django/db/models/manager.py" in
> > _insert
> >   138.         return insert_query(self.model, values, **kwargs)
> > File "/usr/lib/python2.5/site-packages/django/db/models/query.py" in
> > insert_query
> >   888.     return query.execute_sql(return_id)
> > File "/usr/lib/python2.5/site-packages/django/db/models/sql/
> > subqueries.py" in execute_sql
> >   308.         cursor = super(InsertQuery, self).execute_sql(None)
> > File "/usr/lib/python2.5/site-packages/django/db/models/sql/query.py"
> > in execute_sql
> >   1700.         cursor.execute(sql, params)
> > File "/usr/lib/python2.5/site-packages/django/db/backends/util.py" in
> > execute
> >   19.             return self.cursor.execute(sql, params)
>
> > Exception Type: IntegrityError at /admin/store/renter/4/
> > Exception Value: null value in column "rented_by_id" violates not-null
> > constraint
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: wondering how to do something similar to save_model for inline.

2008-12-28 Thread Praveen

This is your database error..

On Dec 28, 8:32 am, Timboy  wrote:
> Great link. I was really excited to try it.
>
> Here is my new inline:
> class rentalInline(admin.TabularInline):
>     model= Rent
>     extra = 3
>     raw_id_fields = ('movie',)
>     exclude = ['rented_by']
>
>     def save_formset(self, request, form, formset, change):
>         instances = formset.save(commit=False)
>         for instance in instances:
>             instance.rented_by = request.user
>             instance.save()
>         formset.save()
>
> I am still getting the same issue:
> Traceback:
> File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py"
> in get_response
>   86.                 response = callback(request, *callback_args,
> **callback_kwargs)
> File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py"
> in root
>   157.                 return self.model_page(request, *url.split('/',
> 2))
> File "/usr/lib/python2.5/site-packages/django/views/decorators/
> cache.py" in _wrapped_view_func
>   44.         response = view_func(request, *args, **kwargs)
> File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py"
> in model_page
>   176.         return admin_obj(request, rest_of_url)
> File "/usr/lib/python2.5/site-packages/django/contrib/admin/
> options.py" in __call__
>   197.             return self.change_view(request, unquote(url))
> File "/usr/lib/python2.5/site-packages/django/db/transaction.py" in
> _commit_on_success
>   238.                 res = func(*args, **kw)
> File "/usr/lib/python2.5/site-packages/django/contrib/admin/
> options.py" in change_view
>   583.                     self.save_formset(request, form, formset,
> change=True)
> File "/usr/lib/python2.5/site-packages/django/contrib/admin/
> options.py" in save_formset
>   382.         formset.save()
> File "/usr/lib/python2.5/site-packages/django/forms/models.py" in save
>   372.         return self.save_existing_objects(commit) +
> self.save_new_objects(commit)
> File "/usr/lib/python2.5/site-packages/django/forms/models.py" in
> save_new_objects
>   407.             self.new_objects.append(self.save_new(form,
> commit=commit))
> File "/usr/lib/python2.5/site-packages/django/forms/models.py" in
> save_new
>   473.         return save_instance(form, new_obj, exclude=
> [self._pk_field.name], commit=commit)
> File "/usr/lib/python2.5/site-packages/django/forms/models.py" in
> save_instance
>   59.         instance.save()
> File "/home/richard/work/svn/moviedb/../moviedb/store/models.py" in
> save
>   91.         super(Rent, self).save(**kwargs)
> File "/usr/lib/python2.5/site-packages/django/db/models/base.py" in
> save
>   307.         self.save_base(force_insert=force_insert,
> force_update=force_update)
> File "/usr/lib/python2.5/site-packages/django/db/models/base.py" in
> save_base
>   379.                 result = manager._insert(values,
> return_id=update_pk)
> File "/usr/lib/python2.5/site-packages/django/db/models/manager.py" in
> _insert
>   138.         return insert_query(self.model, values, **kwargs)
> File "/usr/lib/python2.5/site-packages/django/db/models/query.py" in
> insert_query
>   888.     return query.execute_sql(return_id)
> File "/usr/lib/python2.5/site-packages/django/db/models/sql/
> subqueries.py" in execute_sql
>   308.         cursor = super(InsertQuery, self).execute_sql(None)
> File "/usr/lib/python2.5/site-packages/django/db/models/sql/query.py"
> in execute_sql
>   1700.         cursor.execute(sql, params)
> File "/usr/lib/python2.5/site-packages/django/db/backends/util.py" in
> execute
>   19.             return self.cursor.execute(sql, params)
>
> Exception Type: IntegrityError at /admin/store/renter/4/
> Exception Value: null value in column "rented_by_id" violates not-null
> constraint
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: wondering how to do something similar to save_model for inline.

2008-12-27 Thread Timboy

Great link. I was really excited to try it.

Here is my new inline:
class rentalInline(admin.TabularInline):
model= Rent
extra = 3
raw_id_fields = ('movie',)
exclude = ['rented_by']

def save_formset(self, request, form, formset, change):
instances = formset.save(commit=False)
for instance in instances:
instance.rented_by = request.user
instance.save()
formset.save()

I am still getting the same issue:
Traceback:
File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py"
in get_response
  86. response = callback(request, *callback_args,
**callback_kwargs)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py"
in root
  157. return self.model_page(request, *url.split('/',
2))
File "/usr/lib/python2.5/site-packages/django/views/decorators/
cache.py" in _wrapped_view_func
  44. response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py"
in model_page
  176. return admin_obj(request, rest_of_url)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/
options.py" in __call__
  197. return self.change_view(request, unquote(url))
File "/usr/lib/python2.5/site-packages/django/db/transaction.py" in
_commit_on_success
  238. res = func(*args, **kw)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/
options.py" in change_view
  583. self.save_formset(request, form, formset,
change=True)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/
options.py" in save_formset
  382. formset.save()
File "/usr/lib/python2.5/site-packages/django/forms/models.py" in save
  372. return self.save_existing_objects(commit) +
self.save_new_objects(commit)
File "/usr/lib/python2.5/site-packages/django/forms/models.py" in
save_new_objects
  407. self.new_objects.append(self.save_new(form,
commit=commit))
File "/usr/lib/python2.5/site-packages/django/forms/models.py" in
save_new
  473. return save_instance(form, new_obj, exclude=
[self._pk_field.name], commit=commit)
File "/usr/lib/python2.5/site-packages/django/forms/models.py" in
save_instance
  59. instance.save()
File "/home/richard/work/svn/moviedb/../moviedb/store/models.py" in
save
  91. super(Rent, self).save(**kwargs)
File "/usr/lib/python2.5/site-packages/django/db/models/base.py" in
save
  307. self.save_base(force_insert=force_insert,
force_update=force_update)
File "/usr/lib/python2.5/site-packages/django/db/models/base.py" in
save_base
  379. result = manager._insert(values,
return_id=update_pk)
File "/usr/lib/python2.5/site-packages/django/db/models/manager.py" in
_insert
  138. return insert_query(self.model, values, **kwargs)
File "/usr/lib/python2.5/site-packages/django/db/models/query.py" in
insert_query
  888. return query.execute_sql(return_id)
File "/usr/lib/python2.5/site-packages/django/db/models/sql/
subqueries.py" in execute_sql
  308. cursor = super(InsertQuery, self).execute_sql(None)
File "/usr/lib/python2.5/site-packages/django/db/models/sql/query.py"
in execute_sql
  1700. cursor.execute(sql, params)
File "/usr/lib/python2.5/site-packages/django/db/backends/util.py" in
execute
  19. return self.cursor.execute(sql, params)

Exception Type: IntegrityError at /admin/store/renter/4/
Exception Value: null value in column "rented_by_id" violates not-null
constraint
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: wondering how to do something similar to save_model for inline.

2008-12-27 Thread alex.gay...@gmail.com

Take a look at the save formset method:
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#save-formset-self-request-form-formset-change

On Dec 27, 6:46 pm, Timboy  wrote:
> I have an admin object where I want to pass in the request.user on
> save. It works fine in my normal admin class but not for the inline
> version.
>
> (works fine here):
> class RentAdmin(admin.ModelAdmin):
>     exclude = ['rented_by']
>     list_display = ('renter', 'movie', 'late', 'owed', 'paid',
> 'due_date', 'rented_by')
>     sort_by = '-due_date'
>     raw_id_fields = ('renter', 'movie')
>
> (but not here):
> class rentalInline(admin.TabularInline):
>     model= Rent
>     extra = 3
>     raw_id_fields = ('movie',)
>     exclude = ['rented_by']
>
>     def save_model(self, request, obj, form, change):
>         if not change:
>             obj.rented_by = request.user
>         obj.save()
>
> Any help would be appreciated.
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



wondering how to do something similar to save_model for inline.

2008-12-27 Thread Timboy

I have an admin object where I want to pass in the request.user on
save. It works fine in my normal admin class but not for the inline
version.

(works fine here):
class RentAdmin(admin.ModelAdmin):
exclude = ['rented_by']
list_display = ('renter', 'movie', 'late', 'owed', 'paid',
'due_date', 'rented_by')
sort_by = '-due_date'
raw_id_fields = ('renter', 'movie')

(but not here):
class rentalInline(admin.TabularInline):
model= Rent
extra = 3
raw_id_fields = ('movie',)
exclude = ['rented_by']

def save_model(self, request, obj, form, change):
if not change:
obj.rented_by = request.user
obj.save()

Any help would be appreciated.
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---