Python Social Auth Custom User update - python

I can create new custom user profile with create_profile pipeline function. But also I want to update profile details, if user (or profiles) exist. I couldn't figure out what I need add this function.
utils.py
def create_profile(strategy, backend, details, response, user, *args, **kwargs):
if Profiles.objects.filter(user=user).exists():
if backend.name == 'facebook':
Profiles(user=user).gender = response.get('gender')
Profiles(user=user).fb_link = response.get('link')
Profiles(user=user).timezone = response.get('timezone')
Profiles(user=user).birthdate = response.get('birthday')
Profiles(user=user).email = response.get('email')
Profiles(user=user).fb_id = response.get('id')
else:
new_profile = Profiles(user=user)
if backend.name == 'facebook':
new_profile.gender = response.get('gender')
new_profile.fb_link = response.get('link')
new_profile.timezone = response.get('timezone')
new_profile.birthday = response.get('birthday')
new_profile.email = response.get('email')
new_profile.fb_id = response.get('id')
new_profile.save()
return kwargs
myapp.models.py
class Profiles(models.Model):
user = models.OneToOneField(User, unique=True, null=True)
first_name = models.CharField(max_length=250, blank=True, null=True)
last_name = models.CharField(max_length=250, blank=True, null=True)
middle_name = models.CharField(max_length=200, blank=True, null=True, default="")
profile_img = models.URLField(upload_to='avatars/',null=True, blank=True, default="http://www.murketing.com/journal/wp-content/uploads/2009/04/brightkite.png")
birthdate = models.DateField(null=True, blank=True)
locale = models.CharField(max_length=250, blank=True, null=True)
email = models.CharField(max_length=250, blank=True, null=True)
fb_id = models.BigIntegerField(blank=True, null=True, verbose_name='Facebook ID')

Related

Create list of Approvers Django

I am trying to create an application where you can create project-based expenses, and each project should have a list of approvers who will approve the expense once uploaded to the project, how do I replicate this in Django.
What I tried to do.
I got the approvers into the form as a ModelMultipleChoiceField
self.fields['approvers'] = forms.ModelMultipleChoiceField(queryset=Profile.objects.all())
and saved it as a list into the database
def getApprovers(approvers):
id = []
for profile in approvers:
id.append(profile.id)
return id
in project create function
project.approvers = getApprovers(form.cleaned_data['approvers'])
I created a templatetag to display the list of approvers as the Profile Queryset objects. I tried to iterate over the saved list of approvers, but I keep getting errors
def approvers_list(approvers):
for profile in list(approvers):
profiles = [Profile.objects.filter(pk = i) for i in
list(approvers)]
return profile
I got this error
Field 'id' expected a number but got '['.
This is the result I got after changing the approvers_list method
def approvers_list(approvers):
p = []
for profile in list(approvers):
p.append(profile)
return p
This is the result
['[', '1', ',', ' ', '2', ',', ' ', '3', ']']
How can I turn this into a list of ids, so I can use it to get individual profiles of the approvers?
How can I get this to work best?
Here are the models
class Project(MiscClass):
owner = models.ForeignKey(Profile, on_delete=models.CASCADE, null=True, blank=True)
organisation = models.ForeignKey(Organisation, on_delete=models.SET_NULL, null=True, blank=True)
title = models.CharField(max_length=200, null=True, blank=True, unique=True)
slug = models.SlugField(max_length=500, null=True, blank=True, unique=True)
category = models.ForeignKey('Category', on_delete=models.CASCADE, null=True, blank=True)
description = models.TextField(null=True, blank=True)
approvers = models.CharField(max_length=100, null=True, blank=True, validators=[int_list_validator])
class Meta:
ordering = ['-created']
def __str__(self):
return str(self.title)
def save(self, *args, **kwargs):
self.slug = slugify(self.title)
super(Project, self).save(*args, **kwargs)
class Expense(MiscClass):
PROCESSING = 1
APPROVED = 2
DECLINED = 3
APPROVAL_STATUS = (
(PROCESSING, 'Processing'),
(APPROVED, 'Approved'),
(DECLINED, 'Declined')
)
owner = models.ForeignKey(User, on_delete=models.SET_NULL, blank=True, null=True)
title = models.CharField(max_length=300, null=True)
slug = models.SlugField(max_length=300 , null=True, unique=True)
amount = models.CharField(max_length=200, null=True, blank=True)
status = models.IntegerField(choices=APPROVAL_STATUS, default=PROCESSING)
description = models.TextField(blank=True, null=True)
refrence_number = models.CharField(max_length=300, unique=True, null=True)
category = models.ForeignKey('Category', on_delete=models.SET_NULL, null=True, blank=True)
date_due = models.DateTimeField(auto_now_add=False, null=True, blank=True)
merchant = models.CharField(max_length=200, null=True, blank=True)
expense_date = models.DateTimeField(auto_now_add=False, null=True, blank=True)
def __str__(self):
return str(self.title)
def save(self, *args, **kwargs):
self.slug = slugify(self.title)
return super(Expense, self).save(*args, **kwargs)

How can i update a specific field using foreign key relationship

I want to update a field which is called level. My relation is like this. i am using django User model. Which is extended to Extended user like this below:-
class ExtendedUser(models.Model):
levels_fields = (
("NEW SELLER", "NEW SELLER"),
("LEVEL1", "LEVEL1"),
("LEVEL 2", "LEVEL 2"),
("LEVEL 3", "LEVEL 3")
)
user = models.OneToOneField(User, on_delete=models.CASCADE)
email = models.EmailField(null=True, unique=True)
contact_no = models.CharField(max_length=15, null=True)
profile_picture = models.ImageField(upload_to="images/", null=True)
country = models.ForeignKey(Country, on_delete=models.CASCADE, null=True)
city = models.ForeignKey(City, on_delete=models.CASCADE, null=True)
level = models.CharField(max_length = 120, null=True, blank=True, choices=levels_fields, default="NEW SELLER")
I have a field call "Level" which is full of choices. Now i have a model named Checkout
This is the checkout model :-
class Checkout(models.Model):
ORDER_CHOICES = (
("ACTIVE", "ACTIVE"),
("LATE", "LATE"),
("DELIVERED", "DELIVERED"),
("CANCELLED", "CANCELLED"),
)
user = models.ForeignKey(User, on_delete=models.CASCADE)
seller = models.ForeignKey(
User, on_delete=models.CASCADE, null=True, related_name='seller')
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now_add=True)
first_name = models.CharField(max_length=120)
last_name = models.CharField(max_length=120)
package = models.ForeignKey(OfferManager, on_delete=models.CASCADE)
quantity = models.PositiveIntegerField(default=0)
price = models.DecimalField(decimal_places=2, max_digits=10, default=0.00)
total = models.DecimalField(decimal_places=2, max_digits=10, default=0.00)
grand_total = models.DecimalField(
decimal_places=2, max_digits=10, default=0.00, null=True)
paid = models.BooleanField(default=False)
due_date = models.DateField(null=True)
order_status = models.CharField(max_length=200, choices=ORDER_CHOICES, default="ACTIVE")
is_complete = models.BooleanField(default=False, null=True)
I have another model which is called SellerSubmit and the checkout is the foreign key here. Here is the model :-
class SellerSubmit(models.Model):
checkout = models.ForeignKey(Checkout, on_delete=models.CASCADE, related_name="checkout")
file_field = models.FileField(upload_to="files/", null=True)
submit_date = models.DateField(auto_now_add=True, null=True)
def __str__(self):
return str(self.id)
def save(self, *args, **kwargs):
super().save(*args, **kwargs)
Now when a seller post in the SUbmitModel it will update the level to LEVEL1. How can do it,
This is what i tried :-
def sellerSubmitView(request, pk):
form = SellerSubmitForm()
if request.method == "POST":
file_field = request.FILES.get("file_field")
try:
checkout = Checkout.objects.get(id=pk)
# print(file_field)
except:
return redirect("manage-order")
else:
SellerSubmit.objects.create(checkout=checkout, file_field=file_field)
checkout.order_status ="DELIVERED"
chk = checkout.is_complete = True
l = Checkout.objects.filter(is_complete = True).filter(seller=request.user).count()
print("Count:" + str(l))
if l > 5:
out = checkout.seller.extendeduser.level = "LEVEL1"
print(out)
checkout.save()
print(chk)
checkout.save()
return redirect("manage-order")
args = {
"form": form,
"checkout_id": pk,
}
return render(request, "wasekPart/sellerSubmit.html", args)
checkout.seller.extendeduser.level = "LEVEL1"
checkout.seller.extendeduser.save()
This should solve your problem
out = checkout.seller.extendeduser.level = "LEVEL1"
print(out)
checkout.seller.extendeduser.save()
checkout.save()
It's my bad that didn't notice ExtendedUser is not extended from User.
Please let me know if it's worked or not

Getting a POST request to act like a GET request? djangorestframework-datatables

I don't want to add data to the database, like what djangorestframework-datatables is trying to do with the POST request. I need to use a POST request instead of a GET request because the URI for the GET request is too long (I had to change nginx and gunicorn limits on the production server, to unlimited length (max wasn't enough) which opens the site up to ddos attacks, which is obviously not ideal.
Here is the code:
# api/serializers
class ReportSerializer(serializers.ModelSerializer):
class Meta:
model = Report
fields = "__all__"
# api/views
class ReportViewSet(viewsets.ModelViewSet):
queryset = Report.objects.all()
serializer_class = ReportSerializer
# reports/models
class Report(models.Model):
contribution_expenditure_type = models.CharField(max_length=255, choices=CONTRIBUTION_EXPENDITURE_TYPES)
filer_id = models.BigIntegerField()
filer_namL = models.CharField(max_length=255)
report_num = models.CharField(max_length=255)
committee_type = models.CharField(max_length=255)
rpt_date = models.CharField(max_length=255)
from_date = models.CharField(max_length=255)
thru_date = models.CharField(max_length=255)
elect_date = models.CharField(max_length=255)
rec_type = models.CharField(max_length=255)
form_type = models.CharField(max_length=255, blank=True, null=True)
tran_id = models.CharField(max_length=255, blank=True, null=True)
entity_cd = models.CharField(max_length=255, blank=True, null=True)
tran_namL = models.CharField(max_length=255)
tran_namF = models.CharField(max_length=255, blank=True, null=True)
tran_city = models.CharField(max_length=255, blank=True, null=True)
tran_state = models.CharField(max_length=255, blank=True, null=True)
tran_zip4 = models.CharField(max_length=255, blank=True, null=True)
tran_emp = models.CharField(max_length=255, blank=True, null=True)
tran_occ = models.CharField(max_length=255, blank=True, null=True)
tran_self = models.CharField(max_length=255, blank=True, null=True)
tran_type = models.CharField(max_length=255, blank=True, null=True)
tran_date = models.CharField(max_length=255)
tran_date1 = models.CharField(max_length=255, blank=True, null=True)
tran_amt1 = models.DecimalField(max_digits=10, decimal_places=2)
tran_amt2 = models.DecimalField(max_digits=10, decimal_places=2, default=0)
cmte_id = models.CharField(max_length=255, blank=True, null=True)
intr_namL = models.CharField(max_length=255, blank=True, null=True)
intr_city = models.CharField(max_length=255, blank=True, null=True)
intr_state = models.CharField(max_length=255, blank=True, null=True)
intr_zip4 = models.CharField(max_length=255, blank=True, null=True)
intr_self = models.CharField(max_length=255, blank=True, null=True)
int_cmteId = models.CharField(max_length=255, blank=True, null=True)
efiling_link = models.URLField(blank=True, null=True)
date_report_added = models.DateTimeField(auto_now_add=True, blank=True, null=True)
date_efiling_added = models.DateTimeField(blank=True, null=True)
county = models.ForeignKey(County, on_delete=models.CASCADE, blank=True, null=True)
def __str__(self):
return self.filer_namL
def get_datetime_report_date(self):
return datetime.strptime(self.rpt_date, '%Y-%m-%d %H:%M:%S')
class Meta:
unique_together = ('tran_id', 'form_type')
# api/urls
from django.conf.urls import url
from django.urls import path, include
from rest_framework import routers
from .viewsets import registration_views as reg_views
from . import views
router = routers.SimpleRouter()
# Register router with Viewsets from the registration views file
router.register(r'users', reg_views.UserViewSet, basename="users")
router.register(r'reports', views.ReportViewSet, basename="reports") #/api/v1/reports/
report_list = views.ReportViewSet.as_view({
'get': 'list',
'post': 'retrieve'
})
urlpatterns = [
path('store/', views.api_store, name="store"),
path('stop_store/', views.api_store_stop, name="stop_store"),
path('poll_store_status/', views.poll_store_status, name="poll_store_status"),
path('scrape/', views.api_scrape, name="scrape"),
path('stop_scrape/', views.api_scrape_stop, name="stop_scrape"),
path('poll_scrape_status/', views.poll_scrape_status, name='poll_scrape_status'),
path('get_items/', views.get_items, name="get_items"),
path('get_all_items/', views.get_all_items, name="get_all_items"),
path('get_netviz_reports/', views.get_netviz_reports, name='get_netviz_reports'),
path('get_datatables_items/', report_list, name='report_list'),
]
# main.js
Data.columns = [];
$('th').each(function(item,i){
Data.columns.push({'data': $(this).text().trim()})
});
$('#searchtable').DataTable({
'serverSide': true,
'ajax': {
'url': '/api/get_datatables_items/?format=datatables',
'type': 'POST',
'columns': Data.columns,
'beforeSend': function (request) {
request.setRequestHeader("X-CSRFToken", Cookies.get('csrftoken'));
}
}
});
I'm using djangorestframework, djangorestframework-datatables, and jquery.datatables (frontend). Any help is appreciated.
https://github.com/encode/django-rest-framework/blob/master/rest_framework/mixins.py
Override the create method in ReportViewset
def create(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
#self.perform_create(serializer)
headers = self.get_success_headers(serializer.data)
return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
self.perform_create(serializer) is what access the database.

ValueError: save() prohibited to prevent data loss due to unsaved related object

Hi I am recreating a website in django and this happens...
Django throw this error,
ValueError: save() prohibited to prevent data loss due to unsaved related object 'fk_deal'.
even though I have saved the foreign key related object. This is the view part.
if request.method == "POST":
deal = DEAL()
name = request.POST.get('name')
revenue_2013 = request.POST.get('revenue_2013')
if project_name:
print project_name
deal.name = project_name
deal.save()
print deal.id # prints None
# financials 2013
if revenue_2013:
fin = DEALFINANCIALINFORMATION.objects.create(
financial_category_amount=revenue_2013,
financial_year='2013',
fk_deal = deal,
financial_category_id=1,
)
These are the models....
class DEAL(models.Model):
id = models.BigIntegerField(db_column='ID', primary_key=True) # Field name made lowercase.
company_name = models.CharField(max_length=33L, db_column=u'COMPANY_NAME', blank=True)
investmentrequired = models.FloatField(null=True, blank=True)
is_deleted = MySQLBooleanField(db_column=u'IS_DELETED', blank=True, default=None)
name = models.CharField(max_length=33L, db_column=u'NAME', blank=True)
photo = models.CharField(max_length=66L, db_column=u'PHOTO', blank=True)
status = models.CharField(max_length=85L, db_column=u'STATUS', blank=True)
timestamp = models.DateTimeField(null=True, db_column=u'TIMESTAMP', blank=True)
teaser = models.TextField(db_column=u'TEASER', blank=True)
currency_id = models.BigIntegerField(null=True, db_column=u'CURRENCY_ID', blank=True)
description = models.TextField(db_column=u'DESCRIPTION', blank=True)
country = models.ForeignKey('COUNTRIES', null=True, db_column=u'COUNTRY_ID', blank=True)
sector = models.ForeignKey('SECTORS', null=True, db_column=u'SECTOR_ID', blank=True)
type = models.ForeignKey('TYPES', null=True, db_column=u'TYPE_ID', blank=True)
username = models.CharField(max_length=85L, db_column=u'USERNAME', blank=True)
user = models.ForeignKey('USER', null=True, db_column=u'USER_ID', blank=True)
hitcounter = models.BigIntegerField(null=True, db_column=u'HITCOUNTER', blank=True)
approx_usd = models.DecimalField(decimal_places=2, null=True, max_digits=19, db_column=u'approxUSD', blank=True)
userdeal_id = models.BigIntegerField(null=True, db_column=u'USERDEAL_ID', blank=True)
is_featuredeal = MySQLBooleanField(db_column=u'IS_FEATUREDEAL', blank=True, default=None)
basic_company_email = models.CharField(max_length=33L, db_column=u'BASIC_COMPANY_EMAIL', blank=True)
basic_company_name = models.CharField(max_length=33L, db_column=u'BASIC_COMPANY_NAME', blank=True)
basic_company_phone = models.CharField(max_length=33L, db_column=u'BASIC_COMPANY_PHONE', blank=True)
basic_company_website = models.CharField(max_length=33L, db_column=u'BASIC_COMPANY_WEBSITE', blank=True)
basic_elevator_pitch = models.TextField(db_column=u'BASIC_ELEVATOR_PITCH', blank=True)
basic_premoney_evaluation = models.DecimalField(decimal_places=2, null=True, max_digits=19, db_column=u'BASIC_PREMONEY_EVALUATION', blank=True)
basic_question_1 = models.TextField(db_column=u'BASIC_QUESTION_1', blank=True)
basic_question_2 = models.TextField(db_column=u'BASIC_QUESTION_2', blank=True)
basic_question_3 = models.TextField(db_column=u'BASIC_QUESTION_3', blank=True)
basic_summary = models.TextField(db_column=u'BASIC_SUMMARY', blank=True)
basic_total_offering_amount = models.DecimalField(decimal_places=2, null=True, max_digits=19, db_column=u'BASIC_TOTAL_OFFERING_AMOUNT', blank=True)
is_company = MySQLBooleanField(db_column=u'IS_COMPANY', blank=True, default=None)
is_posted = MySQLBooleanField(db_column=u'IS_POSTED', blank=True, default=None)
is_visible = MySQLBooleanField(db_column=u'IS_VISIBLE', blank=True, default=None)
other_company_milestones = models.TextField(db_column=u'OTHER_COMPANY_MILESTONES', blank=True)
projectname = models.CharField(max_length=33L, db_column=u'PROJECTNAME', blank=True)
basicdealstage = models.ForeignKey('DEALSTAGES', null=True, db_column=u'BASICDEALSTAGE_ID', blank=True)
basic_security_type = models.ForeignKey('SECURITYTYPES', null=True, db_column=u'BasicSecurityType_ID', blank=True)
is_public = MySQLBooleanField(db_column=u'IS_PUBLIC', blank=True, default=None)
profile_completed = models.BigIntegerField(null=True, db_column=u'PROFILE_COMPLETED', blank=True)
is_closed = MySQLBooleanField(db_column=u'IS_CLOSED', blank=True, default=None)
first_step_completed = models.BigIntegerField(null=True, db_column=u'FIRST_STEP_COMPLETED', blank=True, default=0L)
second_step_completed = models.BigIntegerField(null=True, db_column=u'SECOND_STEP_COMPLETED', blank=True)
third_step_completed = models.BigIntegerField(null=True, db_column=u'THIRD_STEP_COMPLETED', blank=True)
class Meta:
db_table = u'DEAL'
def __unicode__(self):
if self.name:
return self.name
else:
return "No name"
class DEALFINANCIALINFORMATION(models.Model):
id = models.BigIntegerField(db_column='ID', primary_key=True) # Field name made lowercase.
financial_category_amount = models.DecimalField(decimal_places=2, null=True, max_digits=19, db_column=u'FINANCIAL_CATEGORY_AMOUNT', blank=True)
financial_year = models.CharField(max_length=33L, db_column=u'FINANCIAL_YEAR', blank=True)
de_al_id = models.BigIntegerField(null=True, db_column=u'DEAl_ID', blank=True)
financial_category_id = models.BigIntegerField(null=True, db_column=u'FINANCIAL_CATEGORY_ID', blank=True)
fk_deal = models.ForeignKey('DEAL', null=True, blank=True)
class Meta:
db_table = u'DEAL_FINANCIAL_INFORMATION'
The database was created from an existing MySQL database....
I send the data to the view using jquery POST....
I can't seem to find out what the problem is. Also even after saving the model if I print the id field it returns None instead....
Can somebody help me?

Django planmember_set issue

I have a question that I hope someone can help me with. I'm using a form to have the user select a "plan". Now I want to list all the members in the plan, in the form. I have a function 'get_owners' that grabs all the members in the plan, by using this function:
def get_owners(self):
owners = self.planmember_set.filter(ownership_type__code__in=["primary","joint"])
return owners
Only problem is that I get an output of:
[<PlanMember: Doe, John (Primary)>, <PlanMember: Doe, Jane(Joint Subscriber)>, etc]
Now is there a way for me to just show their names and the member type (the words in brackets)?
A bit of background code.
Here is my views.py:
if request.POST:
form = PlanMaturityYearForm(Plan.objects.all().filter(profile = p), request.POST)
if form.is_valid():
selected_plan = form.cleaned_data['plans']
plan = get_object_or_404(Plan, pk=selected_plan.pk)
investment_list = Investment.objects.all().filter(Q(plan = plan)).order_by('maturity_date')
context['investment_list'] = investment_list
context['plan'] = plan
context['today'] = now
context['current_yr'] = current_year
context['next_yr'] = next_year
context['show_report'] = True
else:
form = PlanMaturityYearForm(Plan.objects.all().filter(profile = p))
context['form'] = form
return render_to_response('reports/planmaturities_year.html', RequestContext(request, context))
And my forms.py:
class PlanMaturityYearForm(forms.Form):
def __init__(self, plans, *args, **kwargs):
super(PlanMaturityYearForm, self).__init__(*args, **kwargs)
self.fields['plans'] = forms.ModelChoiceField(
plans,
required=True,
widget=forms.Select(attrs={'size': 20}),
error_messages={'required':'Please select the plan you wish to build the report for',}
)
Edit:
models.py
class Plan(models.Model):
old_id = models.IntegerField(null=True)
closed = models.BooleanField(default=False, blank=True)
closed_date = models.DateField(null=True)
profile = models.ForeignKey(Profile, default=False)
plan_type = models.ForeignKey(PlanType)
ownership_type = models.ForeignKey(OwnershipType)
status = models.PositiveSmallIntegerField(max_length=2, default=PLAN_OPEN)
timestamp = models.DateTimeField(auto_now_add=True, null=True, blank=True)
notes = HTMLField(blank=True, null=True)
bank = models.CharField(max_length=50, blank=True, null=True)
account = models.CharField(max_length=50, blank=True, null=True)
transit = models.CharField(max_length=50, blank=True, null=True)
objects = PlanManager()
class Profile(models.Model):
old_id = models.IntegerField(null=True, blank=True)
label = models.CharField(max_length=255, blank=True, verbose_name='Profile label/description')
location = models.ForeignKey(Location, null=True, blank=True)
client = models.BooleanField(default=False, blank=True)
corp = models.BooleanField(default=False, blank=True)
noncorp = models.BooleanField(default=False, blank=True)
timestamp = models.DateTimeField(auto_now_add=True, default=False)
bak_agent_id = models.CharField(max_length=10, null=True, blank=True)
agent = models.ForeignKey(Agent, related_name='profiles')
check1 = models.BooleanField(default=False, blank=True)
incorp_date = models.DateField(null=True, blank=True)
corp_records = models.BooleanField(default=False, blank=True)
articles_of_incorp = models.BooleanField(default=False, blank=True)
other_corp_articles = models.CharField(max_length=50, null=True, blank=True)
bin = models.CharField(max_length=50, null=True, blank=True, verbose_name='BIN')
phone = models.CharField(max_length=25, null=True)
registration = models.CharField(max_length=45, null=True, blank=True)
num_sigs = models.IntegerField(max_length=1, null=True, blank=True,
verbose_name='Number of signatures required to transaction the account')
charity = models.BooleanField(default=False, blank=True)
donations_solicited = models.BooleanField(default=False, blank=True)
ownership_type = models.CharField(max_length=45, null=True, blank=True)
ownership_other = models.CharField(max_length=45, null=True, blank=True) #work around for other business type selction
business_nature = models.CharField(max_length=45, null=True, blank=True)
date_incept = models.DateField(null=True, blank=True)
bind_power = models.BooleanField(default=False, blank=True)
reg_documents = models.BooleanField(default=False, blank=True)
other_documents = models.CharField(max_length=50, null=True, blank=True)
reg_number = models.CharField(max_length=45, null=True, blank=True)
tax_number = models.CharField(max_length=45, null=True, blank=True)
phone = models.CharField(max_length=25, null=True, blank=True)
fax = models.CharField(max_length=25, null=True, blank=True)
email = models.CharField(max_length=100, null=True, blank=True)
You can use values_list:
owners = self.planmember_set.filter(
ownership_type__code__in=["primary","joint"]
).values_list('name', 'type')
def get_owners(self):
owners = self.planmember_set.filter(ownership_type__code__in=["primary","joint"]).values_list('name_field', 'ownership_type__code')
return owners
Write where and how you use get_owners if not correct.

Categories

Resources