Kirby,
This is what i have so far but i dont understand how to get the table to do
what I want. Because all I get on vm_licenses is the ability to select the
vm there is no licenses anymore. I'm not quite sure how all of this works
together.
class License(models.Model):
license_id = models.BigIntegerField(primary_key = True, editable =
False, db_column = 'license_id')
license_authority = models.ForeignKey(License_authoritie, on_delete =
models.PROTECT)
product = models.CharField(max_length = 20)
class Meta:
managed = False
db_table = 'licenses'
ordering = ['product']
def __unicode__(self): # Python 3: def __str__(self):
return self.product
class Vm_license(models.Model):
vm_license_id = models.BigIntegerField(primary_key = True, editable =
False, db_column = 'vm_license_id')
license= models.ManyToManyField(License, through="vm_assignments")
vm= models.ForeignKey(Vm, on_delete = models.PROTECT)
#vm = models.ForeignKey(Vm, on_delete = models.PROTECT)
class Meta:
managed = False
db_table = 'vm_licenses'
class vm_assignments(models.Model):
vm_license = models.ForeignKey(Vm_license, on_delete = models.PROTECT)
license = models.ForeignKey(License, on_delete = models.PROTECT)
On Tuesday, July 15, 2014 12:01:29 PM UTC-6, C. Kirby wrote:
>
> ManyToMany fields actually create a new intermediary join table in the
> database. If you are using an unmanaged database then you will need to
> create the intermediary table yourself. See the ManyToMany field reference
> <https://docs.djangoproject.com/en/dev/ref/models/fields/#manytomanyfield>
>
> On Tuesday, July 15, 2014 12:44:18 PM UTC-5, G Z wrote:
>>
>> <http://www.djangobook.com/en/2.0/_images/book_editform1.png>
>> I will start by saying I have an existing database, for the purpose of my
>> question it has three tables:
>> Vm
>> Vm_licenses
>> Licenses
>>
>> This database is per-existing before we decided to make a django
>> web-portal. Basically licenses is a database that contains all possibile
>> licenses, and Vm contains all the vms under our architecture. We then have
>> a table vm_licenses, where it has a unique index vm_license_id, and two
>> other columns vm_id with is the primary key for VM and license_id which is
>> the primary key for licenses. I want to use the admin page to be able to
>> edit the vm_licenses that way when i select a vm from vm_licenses on the
>> admin page I can select from a list of licenses which licenses go with that
>> vm. The only problem is the database already exist and as far as I can tell
>> the relationship between the tables doesn't exist in a way django can do
>> this with.
>>
>> I have the following model set up:
>>
>> class License(models.Model):
>> license_id = models.BigIntegerField(primary_key = True, editable =
>> False, db_column = 'license_id')
>> license_authority = models.ForeignKey(License_authoritie, on_delete =
>> models.PROTECT)
>> product = models.CharField(max_length = 20)
>>
>> class Meta:
>> managed = False
>> db_table = 'licenses'
>> ordering = ['product']
>>
>> def __unicode__(self): # Python 3: def __str__(self):
>> return self.product
>>
>> class Vm_license(models.Model):
>> vm_license_id = models.BigIntegerField(primary_key = True, editable =
>> False, db_column = 'vm_license_id')
>> license= models.ForeignKey(License, on_delete = models.PROTECT)
>> vm = models.ForeignKey(Vm, on_delete = models.PROTECT)
>>
>> class Meta:
>> managed = False
>> db_table = 'vm_licenses'
>>
>>
>> class Vm(models.Model):
>> vm_id = models.BigIntegerField(primary_key = True, editable = False,
>> db_column = 'vm_id')
>> vm_mor = models.CharField(max_length = 20)
>> vm_name = models.CharField(max_length = 256)
>> vm_group= models.ForeignKey(Vm_group, on_delete = models.PROTECT)
>> vm_display_name = models.CharField(max_length = 30)
>> datacenter= models.ForeignKey(Datacenter, on_delete = models.PROTECT)
>> vcd_managed = models.CharField(max_length = 60)
>>
>> class Meta:
>> managed = False
>> db_table = 'vms'
>>
>> def __unicode__(self): # Python 3: def __str__(self):
>> return self.vm_name
>>
>>
>> My admin page is :
>>
>> class vm_license_admin(admin.ModelAdmin):
>>> list_display = ('vm', 'vm_license_id')
>>> search_fields = ('vm__vm_name',)
>>> ordering = ('vm',)
>>> #filter_horizontal = ('license',)
>>>
>>
>>
>> it says I need a manytomany relationship so I cahnged
>>
>> license= models.ForeignKey(License, on_delete = models.PROTECT)
>>
>> license= models.ManyToManyField(License)
>>
>> but then it says it cant find the table or view from oracle when I change
>> it..
>>
>>
>> How do I fix this I want to be able to assign licenses like the following
>> picture:
>>
>>
>>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/97ee4e48-4630-4320-a4d0-7b282ff6dd5f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.