I'm completely new to JSON and would like to understand how to interpret the following code. Basically, I asked my database to provide me with DB schema and this is what he gave me. I understand SQL and want to create a visual representation of schema of it. Can someone please simplify it.
class Vendor(models.Model):
AUTH_CHOICES = tuple(itertools.chain.from_iterable([(
('KEY', 'KEY'),
('PASSWORD', 'PASSWORD'),
('CUSTOM', 'CUSTOM'),
)]))
name = models.CharField(max_length=32, db_index=True, unique=True)
label = models.CharField(max_length=256, null=True, blank=True)
authentication_type = models.CharField(max_length=32, choices=AUTH_CHOICES, default='KEY')
authentication_inputs = jsonfield.JSONField(null=True, blank=True, default={},
dump_kwargs={'cls': JSONEncoder, 'indent': None,
'separators': (',', ':')})
tags = models.TextField(null=True, blank=True)
categories = models.TextField(null=True, blank=True)
is_hidden = models.BooleanField(default=False)
in_house = models.BooleanField(default=False)
feature = models.ForeignKey(Feature, related_name='vendor_features', null=True, on_delete=models.SET_NULL)
has_multiple_keys = models.BooleanField(default=False)
def __str__(self):
return self.label or self.name
class VendorApi(models.Model):
vendor = models.ForeignKey(Vendor, on_delete=models.SET_NULL, null=True, related_name='apis')
name = models.CharField(max_length=32, db_index=True, unique=True)
label = models.CharField(max_length=256, null=True, blank=True)
plugin = models.CharField(max_length=64, null=True, blank=True)
def __str__(self):
return self.label or self.name
class VendorApiField(models.Model):
GROUP_CHOICES = tuple(itertools.chain.from_iterable([(
('COMPANY', 'COMPANY'),
('PERSON', 'PERSON'),
)]))
TYPE_CHOICES = tuple(itertools.chain.from_iterable([(
('STRING', 'STRING'),
('INTEGER', 'INTEGER'),
('FLOAT', 'FLOAT'),
('CURRENCY', 'CURRENCY'),
('DATETIME', 'DATETIME'),
('OBJECT', 'OBJECT'),
('ARRAY', 'ARRAY'),
('URL', 'URL'),
)]))
vendor_api = models.ForeignKey('VendorApi', related_name='fields', on_delete=models.CASCADE)
name = models.CharField(max_length=64, db_index=True, unique=False)
label = models.CharField(max_length=256, null=True, blank=True)
type = models.CharField(max_length=32, choices=TYPE_CHOICES, default='STRING')
example = models.CharField(max_length=256, null=True, blank=True)
description = models.CharField(max_length=256, null=True, blank=True)
rl_api_field = models.CharField(max_length=64, null=True, blank=True)
group = models.CharField(max_length=32, choices=GROUP_CHOICES, default='COMPANY')
class Meta:
unique_together = ('vendor_api', 'name', 'rl_api_field') ```
From what i can understand from Owners comment and questions. What you need is just to understand how the models are connected. Let me explain it to you.
1.) Vendor is a Model which is connected to another model named feature via foreign key relation(i.e one to many relationship)
2.) Vendor Api connects to Vendor Model via the same foreign key relation as above.
3.) Vendor ApiField connects to VendorApi model via foreign key relation.
To summarise:
Feature <-- Vendor <-- VendorApi <-- VendorApiField
Where <-- shows the relationship via foreign key. (i.e. one to many relationship)in sql
Related
I want to check whether the current user already has the same movie id in his personal list or not. If he has it then I want to exclude that movie from my trending list.
I want it to be something like this.
views.py
trending = list(Movies.objects.exclude(mid in mymovies WHERE uid = request.user.id))
models.py
class Movies(models.Model):
mid = models.CharField(max_length=255, primary_key=True)
title = models.CharField(max_length=255, null=True, blank=True)
rating = models.CharField(max_length=5, null=True, blank=True)
type = models.CharField(max_length=255, null=True, blank=True)
genre = models.CharField(max_length=255, null=True, blank=True)
rdate = models.CharField(max_length=255, null=True, blank=True)
language = models.CharField(max_length=255, null=True, blank=True)
cover = models.CharField(max_length=255, null=True, blank=True)
description = models.TextField(null=True, blank=True)
sequal = models.CharField(max_length=255, null=True, blank=True)
trailer = models.CharField(max_length=255, null=True, blank=True)
year = models.CharField(max_length=5, null=True, blank=True)
objects = models.Manager()
def __str__(self) -> str:
return self.title
class MyMovies(models.Model):
mid = models.ForeignKey(Movies, on_delete=CASCADE)
uid = models.ForeignKey(User, on_delete=CASCADE, null=True, blank=True)
watched = models.BooleanField()
date = models.DateTimeField(auto_now_add=True)
objects = models.Manager()
You can .exclude(…) with:
trending = Movies.objects.exclude(mymovies__uid=request.user)
If you specified a related_query_name=… [Django-doc] or a related_name=… [Django-doc], then you need to use that to make a JOIN with your Movies model:
trending = Movies.objects.exclude(related_name_of_fk__uid=request.user)
Note: normally a Django model is given a singular name, so MyMovie instead of MyMovies.
Note: Normally one does not add a suffix _id to a ForeignKey field, since Django
will automatically add a "twin" field with an _id suffix. Therefore it should
be user, instead of uid.
I have a ForeignKey field in my model and in Django admin and Django forms` when I display that field or in Django admin, I get all the field that in that model However, I only want to display selected fields in that dropdown, for example
class Area(models.Model):
area_type_options = (('cc', 'Cost Center'), ('pc', 'Profit Center'),)
name = models.CharField(max_length=100)
area_type = models.CharField(max_length=100, choices=area_type_options)
class Item(models.Model):
name = models.CharField(max_length=150, null=True, unique=True)
profit_center = models.ForeignKey(Area, null=True, blank=True, on_delete=models.CASCADE, related_name='profit_center')
cost_center = models.ForeignKey(Area, null=True, blank=True, on_delete=models.CASCADE, related_name='cost_center')
I get to see all the records in the cost_center and all the records in the profit_center however I only want to see where area_type is cc to cost_center and where area type pc to profit_center
Please Help
You can use ForeignKey.limit_choices_to [Django docs] to do this:
class Item(models.Model):
name = models.CharField(max_length=150, null=True, unique=True)
profit_center = models.ForeignKey(Area, null=True, blank=True, on_delete=models.CASCADE, related_name='profit_center', limit_choices_to={'area_type': 'pc'})
cost_center = models.ForeignKey(Area, null=True, blank=True, on_delete=models.CASCADE, related_name='cost_center', limit_choices_to={'area_type': 'cc')
I have a Django model "Inspection" which has:
InspectionID (PK)
PartID
SiteID
Date
Comment
Report
Signiture
I want to be able to have a one to many relationship between the inspection ID and date. So one ID can have inspections at many dates. How would I do this? I currently have the following:
class Inspection(models.Model):
InspectionID = models.IntegerField(primary_key=True, unique=True)
PartID = models.ForeignKey('Part', on_delete=models.CASCADE)
SiteID = models.ForeignKey('Site', on_delete=models.CASCADE)
Date = models.DateField(auto_now=False, auto_now_add=False)
Comment = models.CharField(max_length=255, blank=True)
Report = models.FileField(upload_to='docs', null=True, blank=True)
Signiture = models.CharField(max_length=255, blank=True)
I thought about using models.ForeignKey but I really don't know how to implement that properly in this situation.
I want to be able to have a one to many relationship between the inspection ID and date.
You create an extra model, like:
class InspectionDate(models.Model):
inspection = models.ForeignKey(
Inspection,
on_delete=models.CASCADE,
related_name='inspectiondates'
)
date = models.DateField()
You thus can create InspectionDates for a given Inspection.
Or if you want to add extra data, it might be better to define an InspectionGroup model:
class InspectionGroup(models.Model):
pass
class Inspection(models.Model):
id = models.AutoField(primary_key=True, unique=True, db_column='InspectionId')
inspectiongroup = models.ForeignKey(InspectionGroup, on_delete=models.CASCADE, db_column='InspectionGroupId')
part = models.ForeignKey('Part', on_delete=models.CASCADE, db_column='PartId')
site = models.ForeignKey('Site', on_delete=models.CASCADE, db_column='SiteId')
date = models.DateField(db_column='Date')
comment = models.CharField(max_length=255, blank=True, db_column='CommentId')
report = models.FileField(upload_to='docs', null=True, blank=True, db_column='ReportId')
signiture = models.CharField(max_length=255, blank=True, db_column='Signature')
Note: the name of attributes are normally written in snake_case [wiki], not in PerlCase or camelCase.
you may store 'self Foriegnkey' as
class Inspection(models.Model):
InspectionID = models.IntegerField(primary_key=True, unique=True)
PartID = models.ForeignKey('Part', on_delete=models.CASCADE)
SiteID = models.ForeignKey('Site', on_delete=models.CASCADE)
Date = models.DateField(auto_now=False, auto_now_add=False)
Comment = models.CharField(max_length=255, blank=True)
Report = models.FileField(upload_to='docs', null=True, blank=True)
Signiture = models.CharField(max_length=255, blank=True)
inspection_id = models.ForeignKey('self', null=True, blank=True)
Attached below is the models.py I used for my project,
I've attached the photos of the issue as well.
Issue 1
For some reason, all the contents of the tables are not being displayed.
In the first table, first content goes missing.
In the Second table, First and the second contents go missing
Issue 2
The Inline function doesn't work. I tried going through the documentation and several youtube videos to find out how to handle the situation but it didn't help much.
Issue 3
For the bug table, When I select the project name, How do I ensure that only the people I added to that project table are allowed to be selected?
Issue 4
Is there a way to extract the email ID from the Users page and and when I choose the name of the user in the Project page, the email Id will be automatically filled it?
Same way, In the issues page, when I choose the user, the email Id will be auto entered.
MODELS.py
from django.db import models
# Create your models here.
from django.contrib.auth.models import User
from django.db import models
from django.core.mail import EmailMessage
from django.contrib import admin
# Create your models here.
class Project(models.Model):
STATUS_CHOICE = (
('Project Manager', 'Project Manager'),
('Technician', 'Technician'),
('Tester', 'Tester')
)
STATUS_CHOICE_1 = (
('Work Assigned', 'Work Assigned'),
('Work in Progress', 'Work in Progress'),
('Testing', 'Testing'),
('Completed', 'Completed')
)
Project_Name = models.CharField(max_length=100)
Project_Description = models.CharField(max_length=100)
Admin_Name = models.ForeignKey(User, on_delete=models.CASCADE, related_name='User.Admin_Name_users+')
Admin_Mail_ID = models.EmailField(max_length=50)
Project_Manager_1 = models.ForeignKey(User, on_delete=models.CASCADE, related_name='User.Project_Manager_1_users+')
Project_Manager_1_Mail_ID = models.EmailField(max_length=50)
Project_Manager_2 = models.ForeignKey(User, on_delete=models.CASCADE, related_name='User.Project_Manager_2_users+', blank=True, null=True)
Project_Manager_2_Mail_ID = models.EmailField(max_length=50, blank=True, null=True)
Technician_1 = models.ForeignKey(User, on_delete=models.CASCADE, related_name='User.Technician_1_users+')
Technician_1_Mail_ID = models.EmailField(max_length=50)
Technician_2 = models.ForeignKey(User, on_delete=models.CASCADE, related_name='User.Technician_2_users+', blank=True, null=True)
Technician_2_Mail_ID = models.EmailField(max_length=50, blank=True, null=True)
Technician_3 = models.ForeignKey(User, on_delete=models.CASCADE, related_name='User.Technician_3_users+', blank=True, null=True)
Technician_3_Mail_ID = models.EmailField(max_length=50, blank=True, null=True)
Tester_1 = models.ForeignKey(User, on_delete=models.CASCADE, related_name='User.Tester_1_users+')
Tester_1_Mail_ID = models.EmailField(max_length=50, default='Example#gmail.com')
Additional_User_1 = models.ForeignKey(User, on_delete=models.CASCADE, related_name='User.Ad_1_users+', blank=True, null=True)
Additional_User_1_Type = models.CharField(max_length=18, choices=STATUS_CHOICE, blank=True, null=True)
Additional_User_1_Mail_ID = models.EmailField(max_length=50, blank=True, null=True)
Additional_User_2 = models.ForeignKey(User, on_delete=models.CASCADE, related_name='User.Ad_1_users+', blank=True, null=True)
Additional_User_2_Type = models.CharField(max_length=18, choices=STATUS_CHOICE, blank=True, null=True)
Additional_User_2_Mail_ID = models.EmailField(max_length=50, blank=True, null=True)
Additional_User_3 = models.ForeignKey(User, on_delete=models.CASCADE, related_name='User.Ad_1_users+', blank=True, null=True)
Additional_User_3_Type = models.CharField(max_length=18, choices=STATUS_CHOICE, blank=True, null=True)
Additional_User_3_Mail_ID = models.EmailField(max_length=50, blank=True, null=True)
Status_of_the_project = models.CharField(max_length=18, choices=STATUS_CHOICE_1)
Created = models.DateTimeField(auto_now_add=True, null=True, blank=True)
Finish_Date = models.DateTimeField(null=True, blank=True)
Supporting_Documents = models.FileField(null=True, blank=True)
class FlatPageAdmin(admin.ModelAdmin):
fieldsets = (
(None, {
'fields': ('Project_Name','Project_Description','Admin_Name','Admin_Mail_ID','Project_Manager_1','Project_Manager_1_Mail_ID',
'Technician_1','Technician_1_Mail_ID','Tester_1','Tester_1_Mail_ID','Status_of_the_project','Created','Finish_Date','Supporting_Documents',
)
}),
('Add More Users', {
'classes': ('collapse',),
'fields': ('Project_Manager_2','Project_Manager_2_Mail_ID','Technician_2','Technician_2_Mail_ID',
'Technician_3','Technician_3_Mail_ID','Additional_User_1','Additional_User_1_Type',
'Additional_User_1_Mail_ID','Additional_User_2','Additional_User_2_Type','Additional_User_2_Mail_ID',
'Additional_User_3','Additional_User_3_Type','Additional_User_3_Mail_ID'),
}),
)
def __str__(self):
return self.Project_Name
class Meta:
verbose_name_plural = "List Of Projects"
class Bug(models.Model):
STATUS_CHOICE = (
('Unassigned', 'Unassigned'),
('Assigned', 'Assigned'),
('Testing', 'Testing'),
('Tested', 'tested'),
('Fixed', 'Fixed')
)
STATUS_CHOICE_1 = (
('Bug', 'Bug'),
('Issue', 'Issue'),
('Enhancement', 'Enhancement'),
('Not an issue or bug', 'Not an issue or bug'),
('Fixed', 'Fixed')
)
Project = models.ForeignKey(Project, on_delete=models.CASCADE)
Issue_Title = models.CharField(max_length=50, blank=True, null=True)
Situation_Type = models.CharField(max_length=25, choices=STATUS_CHOICE_1)
Basic_Description = models.CharField(max_length=100)
Detailed_Description = models.TextField(default='The Description, here.')
Status = models.CharField(max_length=18, choices=STATUS_CHOICE)
Assigned_to = models.ForeignKey(User, on_delete=models.CASCADE)
Assigned_to_Mail_ID = models.EmailField(max_length=50, blank=True, null=True)
Admin_Mail_ID = models.EmailField(max_length=50, blank=True, null=True)
Reported_by = models.CharField(max_length=50, blank=True, null=True)
Reporters_Mail_ID = models.EmailField(max_length=50, blank=True, null=True)
Reported_Date = models.DateTimeField(null=True, blank=True)
Created = models.DateTimeField(auto_now_add=True, null=True, blank=True)
Updated = models.DateTimeField(auto_now=True, null=True, blank=True)
Deadline_Date = models.DateTimeField(null=True, blank=True)
Supporting_Documents_By_Reporter = models.FileField(null=True, blank=True)
Project_Managers_Comment = models.TextField(default='The Description, here.')
Supporting_Documents_by_Project_Manager = models.FileField(null=True, blank=True)
Technicians_Comment = models.TextField(default='The Description, here.')
Supporting_Documents_by_Technician = models.FileField(null=True, blank=True)
Testers_Comment = models.TextField(default='The Description, here.')
Supporting_Documents_by_Tester = models.FileField(null=True, blank=True)
def __str__(self):
return '{} ({}) [{}]'.format(self.Project, self.Situation_Type, self.Status, self.Issue_Title)
def save(self, force_insert=False, force_update=False, using=None,
update_fields=None):
if self.id:
user=self.Assigned_to
self.Assigned_to_Mail_ID=user.email
send_mail(self.Admin_Mail_ID, ass=self.Assigned_to_Mail_ID)
super(Bug, self).save()
class Meta:
verbose_name_plural = "Projects Tasks/Issues"
def send_mail(admin,ass):
email=EmailMessage('Changes made to Task','Changes have been made to one of your Task reports and we hereby request you to have a look at it at the earliest.', to=[admin,ass])
email.send()
I've also attached the admin.py file as well.
Admin.py
from django.contrib import admin
from .models import Bug, Project
from django.contrib.admin.models import LogEntry
admin.site.register(LogEntry)
# Register your models here.
class BugDisplay(admin.ModelAdmin):
list_display = ('Project', 'Status', 'Basic_Description', 'Assigned_to', 'Created', 'Updated', 'Issue_Title')
list_filter = ('Status', 'Assigned_to', 'Project')
search_fields = ('Reporters_Mail_ID', 'Reported_by', 'Basic_Description',)
admin.site.register(Bug, BugDisplay)
# Register your models here.
#admin.register(Project)
class ProjectDisplay(admin.ModelAdmin):
list_display = ('Project_Name','Admin_Name', 'Project_Manager_1', 'Status_of_the_project')
list_filter = ('Admin_Name', 'Status_of_the_project')
search_fields = ('Project_Name', 'Project_Description', 'Admin_Name', 'Admin_Mail_ID', 'Project_Manager_1 '
'Project_Manager_1_Mail_ID', 'Project_Manager_2 ', 'Project_Manager_2_Mail_ID',
'Technician_1',
'Technician_1_Mail_ID', 'Technician_2', 'Technician_2_Mail_ID', 'Technician_3',
'Technician_3_Mail_ID', 'Tester_1', 'Tester_1_Mail_ID', 'Additional_User_1', 'Additional_User_1_Type',
'Additional_User_1_Mail_ID', 'Additional_User_2', 'Additional_User_2_Type', 'Additional_User_2_Mail_ID',
'Additional_User_3', 'Additional_User_3_Type', 'Additional_User_3_Mail_ID', 'Status_of_the_project', 'Created',
'Finish_Date', 'Supporting_Documents')
As per your question please provide your admin inline class (referring to issue 2) and please elaborate for issue 1 and provide more details.
Regarding issue 2 you can override appropriate field using this. You can provide your custom queryset(by applying your filter conditions) to the foreign key field.
def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == 'your_field_name':
kwargs["queryset"] = your_custom_queryset_based_on_conditions
return super().formfield_for_foreignkey(db_field, request, **kwargs)
For issue 4, you want email Id to be auto filled based on user selection. This can be achieved using custom javascript.
Another way could be that, you do not show email field and while saving the record from project/issue admin you automatically fetch email id from users table and assign it to the object and save it.
You may have a look at this, to customize while saving the object from admin panel.
def save_model(self, request, obj, form, change):
email = your_method_to_find_email_for_user(obj.user_field)
obj.email_field = email
super().save_model(request,obj,form,change)
I am trying to use the "limit_choices_to" functionality in a Django OneToOneField where upstream of what I want to limit the choices on is another ForeignKey. The error I get in the admin with the way I have it set up is:
invalid literal for int() with base 10: 'Storage Array'
I assume this is because it is looking at the actual value in the column asset_type which is an integer foreign key. I need to be able to limit the choices based on a field value of the foreign key as opposed to the key value itself.
Basically what I am trying to accomplish is having the admin area (and other forms) only allow you to choose a valid asset type when adding a new asset. For example, if I am adding a "storage array" the upstream asset tied to it should only be allowed to be asset_type of storage array.
Here is my model:
from django.db import models
from localflavor.us.us_states import STATE_CHOICES
# Table of brand names of assets
class Brand(models.Model):
brand = models.CharField(max_length=128, unique=True)
def __unicode__(self):
return self.brand
# Table of device types for assets, e.g. "Storage Array"
class Device(models.Model):
device_type = models.CharField(max_length=128, unique=True)
device_url_slug = models.SlugField(max_length=70, unique=True)
class Meta:
verbose_name = "device type"
verbose_name_plural = "device types"
def __unicode__(self):
return self.device_type
# Table of asset locations
class Location(models.Model):
site_name = models.CharField(max_length=128, unique=True)
site_nick = models.CharField(max_length=5, unique=True)
address_line_one = models.CharField(max_length=256)
address_line_two = models.CharField(max_length=256, null=True, blank=True)
address_city = models.CharField(max_length=32)
address_state = models.CharField(max_length=2, choices=STATE_CHOICES, null=True, blank=True)
address_zip = models.CharField(max_length=5)
def __unicode__(self):
return self.site_name
# Table of Environments, e.g. "Production"
class Environment(models.Model):
environment = models.CharField(max_length=128, unique=True)
def __unicode__(self):
return self.environment
class Credentials(models.Model):
AUTH_CHOICES = (
('SSH', 'Standard SSH'),
('SSH-Key', 'SSH with Key-based login'),
('HTTP', 'Standard HTTP'),
('HTTPS', 'Secure HTTP'),
('API', 'API Based'),
('SNMP', 'SNMP Based'),
)
SNMP_VERSIONS = (
('v1', 'SNMP v1'),
('v3', 'SNMP v3'),
)
auth_method = models.CharField(max_length=32, choices=AUTH_CHOICES)
auth_username = models.CharField(max_length=32)
auth_password = models.CharField(max_length=32, null=True, blank=True)
auth_snmp_version = models.CharField(max_length=2, choices=SNMP_VERSIONS, null=True, blank=True)
auth_snmp_community = models.CharField(max_length=128, null=True, blank=True)
class Meta:
verbose_name = "credentials"
verbose_name_plural = "credentials"
def __unicode__(self):
return self.auth_method
class Asset(models.Model):
asset_name = models.CharField(max_length=128, unique=True)
asset_type = models.ForeignKey(Device)
brand = models.ForeignKey(Brand)
model = models.CharField(max_length=128)
serial = models.CharField(max_length=256)
location = models.ForeignKey(Location)
environment = models.ForeignKey(Environment)
datacenter_room = models.CharField(max_length=32, null=True, blank=True)
grid_location = models.CharField(max_length=32, null=True, blank=True)
mgmt_address = models.CharField(max_length=128)
notes = models.TextField(null=True, blank=True)
def __unicode__(self):
return self.asset_name
class StorageArray(models.Model):
OS_NAME_CHOICES = (
('Data OnTap', 'NetApp Data OnTap'),
)
OS_TYPE_CHOICES = (
('7-Mode', 'NetApp 7-Mode'),
('cDOT', 'NetApp Clustered'),
)
HA_TYPE_CHOICES = (
('Standalone', 'Standalone System'),
('HA Pair', 'HA Pair'),
('Clustered', 'Clustered'),
)
asset = models.OneToOneField(Asset, primary_key=True, limit_choices_to={'asset_type': 'Storage Array'})
os_name = models.CharField(max_length=32, choices=OS_NAME_CHOICES, null=True, blank=True)
os_version = models.CharField(max_length=16, null=True, blank=True)
os_type = models.CharField(max_length=16, choices=OS_TYPE_CHOICES, null=True, blank=True)
array_ha_type = models.CharField(max_length=32, choices=HA_TYPE_CHOICES, null=True, blank=True)
array_partner = models.CharField(max_length=128, null=True, blank=True)
credentials = models.ForeignKey(Credentials, null=True, blank=True)
class Meta:
verbose_name = "storage array"
verbose_name_plural = "storage arrays"
def __unicode__(self):
return self.asset.asset_name
class SANSwitch(models.Model):
OS_NAME_CHOICES = (
('FabricOS', 'Brocade FabricOS'),
)
SWITCH_TYPE_CHOICES = (
('Standalone', 'Standalone Switch'),
('Director', 'Director'),
('Router', 'Multiprotocol Router'),
('Blade', 'Blade Chassis IO Module'),
)
SWITCH_ROLE_CHOICES = (
('Core', 'Core'),
('Edge', 'Edge'),
('AG', 'Access Gateway'),
)
asset = models.OneToOneField(Asset, primary_key=True, limit_choices_to={'asset_type': 'SAN Switch'})
os_name = models.CharField(max_length=32, choices=OS_NAME_CHOICES, null=True, blank=True)
os_version = models.CharField(max_length=16, null=True, blank=True)
switch_type = models.CharField(max_length=32, choices=SWITCH_TYPE_CHOICES, null=True, blank=True)
switch_role = models.CharField(max_length=32, choices=SWITCH_ROLE_CHOICES, null=True, blank=True)
credentials = models.ForeignKey(Credentials, null=True, blank=True)
class Meta:
verbose_name = "san switch"
verbose_name_plural = "san switches"
def __unicode__(self):
return self.asset.asset_name
I fixed it all by myself!
It seems to translate further down a relationship you can make use of the double underscore notation that python/django has built in.
To fix my issue:
asset = models.OneToOneField(Asset, primary_key=True, limit_choices_to={'asset_type': 'Storage Array'})
became:
asset = models.OneToOneField(Asset, primary_key=True, limit_choices_to={'asset_type__device_type': 'Storage Array'})