>From my limited understanding of Django...

the admin.py stuff should not contain any save function.

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#ref-contrib-admin

what exactly are you trying to do with the tag? Your M2M field in the
initial Game class creates the relationship.

You may want to looking into using the django-tagging app, which is
what i used for my stupid little blog app (doesn't everyone create
that first? lol )

If it helps, the first thing i did when learning django is follow the
webmonkey.com django tutorial 
http://www.webmonkey.com/tutorial/Install_Django_and_Build_Your_First_App

i found this infinitely more useful than the tutorial on
djangoproject.com, as it goes into things a bit more complex and gives
a greater idea on how things work together in the framework.

Also, don't underestimate the framework... it does a lot of things for
you, which is the point. It allows you to build an app quickly without
worrying about the annoyances of SQL.

On Feb 4, 2:13 pm, GeneralMean <marcin.wtorkow...@gmail.com> wrote:
> Thanks for the answer,
>
> I modified my Game model according to your suggestion, and also,
> simplified whole thing.
> I can create new game without having to choose any tags - that's
> correct. Now, take a look at
> the save_model() method in GamesAdmin - I try to associate newly
> created Game with some
> tag -- with no luck :/ Looks like django admin application prevents
> from actual saving _any_ relationship
> inside save_model in save() method of Game model as well - tested).
> Any ideas how to force create of m2m relationship after the form got
> submited, without using raw SQL query?
>
> Current code:
>
> #in models.py
> class Game(models.Model):
>     id = models.AutoField(primary_key=True, db_column='grg_id')
>     tags = models.ManyToManyField(Tag, blank=True, null=True,
> related_name='g_tags')
>
> class Tag(models.Model):
>     id = models.AutoField(primary_key=True, db_column='grt_id')
>     tag = models.CharField(max_length=255, unique=True,
> db_column='grt_tag')
>     tag_url = models.CharField(max_length=255, blank=False,
> db_column='grt_tag_url')
>     tag_keyword = models.CharField(max_length=255, blank=False,
> db_column='grt_tag_keyword')
>
> #in admin.py
> class GamesAdmin(admin.ModelAdmin):
>     #NOT using custom form anymore
>     #form = GamesAdminModelForm
>
>     def save_model(self, request, obj, form, change):
>         super(GamesAdmin, self).save_model(request, obj, form, change)
>         if not change:
>             #get a tag
>             tag = Tags.objects.get(pk=1)
>             #associate tag with newly created object
>             obj.tag.add(tag)
>
> admin.site.register(Game)
> admin.site.register(Tag)
>
> On 4 Lut, 19:15, garagefan <monkeygar...@gmail.com> wrote:
>
> > Not totally sure this will help with your error, as i haven't come
> > across it yet.
>
> > But for fields that may be empty I also have a blank = True and null =
> > True. This is to tell the DB that it is acceptable to have no value in
> > the field.
>
> > ie, i'm using the following to choose add users to a private forum
> > category:
>
> > allowedUsers = models.ManyToManyField(User, verbose_name=_('Members'),
> > blank=True, null=True,
> >                 help_text=_('Select Users that are allowed to view this 
> > private
> > group'), limit_choices_to={'is_staff': False}
> >                 )
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to