Re: can't delete many-to-many related record from admin inline

2008-11-01 Thread ndarkduck

I'm no guru, Im  stuck  also with some many-to-many features.

1.- why whould you need a  3rd  table if you are not using attributes
in the relationship? (Variant).
2.- have you tried to add an models.AutoField(primary=True) to your
model Variant ? I knew django does that if no is specified in order to
preserve the 3rd normal form, but it would be a first aproach.

Hope this helped out a little.

Regards
ndarkduck

On Oct 30, 7:40 am, chris <[EMAIL PROTECTED]> wrote:
> Hi there,
>
> I am still pretty new to django and just trying to figure out how it
> is all supposed to work.
>
> I have the following models:
>
> *models.py:
>
> class Char(models.Model):
>     char = models.CharField(max_length=10)
>     variants = models.ManyToManyField("self", symmetrical=False,
> through="Variant", related_name="varchars", blank=True, null=True)
>
> class Variant(models.Model):
>      char = models.ForeignKey(Char)
>      variant = models.ForeignKey(Char, related_name="vars")
>
> *admin.py:
>
> class CharVarInline(admin.StackedInline):
>       model = Variant
>       fk_name = "char"
>       raw_id_fields=("variant", "char",)
>       extra = 1
>
> class CharAdmin(admin.ModelAdmin):
>     inlines = (CharVarInline,)
>
> This causes the variants part to be displayed with a char record in
> admin.  I also get a check-box there, which can be checked to delete
> the inlined related recorded.   However, when I try to used this to
> delete the record and click save, the following error occurs:
>
> ValueError at /admin/chardb/char/70524/
>
> 'Variant' instance needs to have a primary key value before a many-to-
> many relationship can be used.
>
> Apparently, something is going wrong with the deletion, which lets
> part of the record hang in empty air.  But I have no idea where to
> look or how to fix this.  Does anybody has any idea?
>
> Any help appreciated,
>
> Chris
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



ManyToMany views

2008-10-30 Thread ndarkduck

Hi, thanks for making a mailing list about inqueries.

I want to know if is possible to autogenerate a view that allows a
many to many relationship with an extra field to be captured.

ie:

class statictests(models.Model):
   statictests_id = models.AutoField(primary_key=True);
statictests_name = models.CharField(max_length=90);

class proyect(models.Model):
   tests = models.ManyToManyField(statictests, through =
'num_tests');

class num_tests_unidades(models.Model):
un_alt_tec = models.ForeignKey(statictests);
res_proy_ver = models.ForeignKey(proyect);
num_tests = models.IntegerField();

The view that results from this code is:
--

bababa.
bebe.
bibi
etc1.
etc2.

-
I need something that specifies the attribute of the relationship.

Thanks in advance


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---