Re:

2018-05-23 Thread tango ward
Check if your template name is correct in your views.py

On Wed, May 23, 2018 at 5:56 PM, Umar Kambala  wrote:

> Plz need help
> I found this problem TemplateDoesNotExit at /polls/1/ where might have I
> gone wrong?
>
> --
> 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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAPkbFbZwVPyBpVsA65UTjeJNgKHnQ
> qpsTVmOmeO5GFeusnVfww%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLLkxWQd3wDOMPNDEAPPNeTfVJhU7L1GP4au75yrU6Bcuw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Control PhoneNumber Format in SQL

2018-05-15 Thread tango ward
Hi,

I am currently migrating database from MySQL to PostgreSQL. I have already
migrated some of the data but I can't pull the data for my phonenumber
field.

I have a model:

class BasePerson(TimeStampedModel):
 phone_number = PhoneNumberField(max_length=50, verbose_name=_(u'phone
number'), blank=True)


The data for phone number that I am migrating doesn't have country code. I
would like to know if I can control this in SQL? I want to determine first
if the number has country code in it, if it doesn't then I will add the
country code on the number before INSERTING it to the destination database.
I am using psycopg2 for my script.


Any suggestion will be highly appreciated.


Thanks,
J

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQL%2Bf%3DkBHowTs-J3%3DQxwR2UFMZq1Jk3d-%2BWMnDPsK1rr%3D0A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


UpdateView Decimal Field Initial Value

2018-04-24 Thread tango ward
Hi,


I am working on an UpdateView of a form. I am having hard time displaying
the initial value of grades per subject. I can display the subjects fine in
the template, however I can't display the grades using the DecimalField. If
change DecimalField to ModelChoiceField in forms.py, I can view the grades
in a drop down menu in template but this is not what I want. I want the
user to be able to edit using DecimalField.

forms.py
class GradeUpdateForm(CrispyFormMixin, forms.ModelForm):
s_name = forms.ModelChoiceField(queryset=Subject.objects.none(),
empty_label=None)
final_grade =
forms.DecimalField(widget=forms.NumberInput(attrs={'style':'width:80px'}),
decimal_places=2, max_digits=5,)
class Meta:
model = SGrade
fields = [
's_name',
'final_grade',
]

I tried playing around with for loop in my views but no good.

views.py
class SchoolDashboardGradesUpdateView(SchoolStudentMixin, UpdateView):
template_name = 'education/dashboard/grades_update.html'
model = SubjectGrade
form_class = GradeUpdateForm

# def get_object(self):
# return get_object_or_404(Recipient, pk=self.kwargs['pk'])

def get(self, request, *args, **kwargs):
self.object = None
form_class = self.get_form_class()
form = self.get_form(form_class)
form.fields['subject_name'].queryset = Subject.objects.filter(

sgrade__recipient__id=self.kwargs.get('pk'),

sgrade__status='approved').values_list('name', flat=True)
form.fields['final_grade'].queryset = SGrade.objects.filter(

recipient__id=self.kwargs.get('pk'),

status='approved').values_list('final_grade', flat=True)
student = Student.objects.get(id=self.kwargs.get('pk')
for x in student.sgrade_set.all():
 if x.status == 'approved':
  forms.fields['final_grade'].initial = x.final_grade

for st in student.subjectgrade_set.all():
if st.status == 'approved':
test_dict[st.subject.name] = st.final_grade

print test_dict
for key, value in test_dict.iteritems():
if key in subject_names:
form.fields['final_grade'].initial = value

I also tried putting the keys and values in a dictionary and in my html

template



  {% for instance in form.subject_name.field.choices %}

 {{instance.1}}
 {{form.final_grade}}


  {% endfor %}


test_dict = {}


Reverse for '' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

2018-04-18 Thread tango ward
Hi,

I just need some suggestions with this error that I am getting. I searched
some related posts in Stackoverflow but most of the posts related were
problems with urls.py or name in urls. My issue is that the page loads if I
just put a plain HTML text in the page but the error occurs when I try to
use extend template tags.

Here's the my in stackoverflow:
https://stackoverflow.com/questions/49910783/django-error-reverse-for-with-arguments-and-keyword-arguments-not?noredirect=1#comment86838457_49910783

Any suggestions will be highly appreciated.


Thanks,
J

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLLD8Pvr06b9573PNWrxn8m2At6DjAFARGP1eRsfi6Lp8A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Tips On Migrating DB from other website to django with Postgresql

2018-04-11 Thread tango ward
Sorry for the follow up question, when you say run migration locally, this
is running python manage.py makemigrations and python manage.py migrate,
right?  Please let me know if I got these steps correctly:

- make a postgres test db
- changed database settings in settings.py and point it to test db in
postgres
- If i run makemigrations and migrate, the only db and tables that will be
saved in test db are the ones in our models.py

Should I modify the models.py to match the fields in the dump file? or
should I just check the existing data from the dump file and see which
model and fields it fits in our existing system?

My only experience with changing backend database in Django was when I
changed one of my pet projects db from SQLite to Postgres which I did in
settings.py.

On Thu, Apr 12, 2018 at 8:59 AM, tango ward <tangowar...@gmail.com> wrote:

> At the moment, I am comparing the fields from the dump file and the fields
> in our models.py. There are fields that exist on the dump file that are not
> yet in our existing model/models that why I want to know if should I modify
> the schema of our database to match the dump file of the client. I'm lost
> on this, sorry.
>
> On Thu, Apr 12, 2018 at 8:46 AM, Mike Dewhirst <mi...@dewhirst.com.au>
> wrote:
>
>> On 12/04/2018 9:47 AM, tango ward wrote:
>>
>>> Hi Mike,
>>>
>>>
>>> Thanks for the advice.
>>>
>>> May I ask as well, on Django side, since we have already an existing
>>> system, how should I adjust the fields that are existing from the dump file
>>> to the Django? Should I just add fields in models.py?
>>>
>>
>> Treat that as a separate task. You can do it before the migration or
>> after. I would preferdo it afterwards because I am more comfortable with
>> Postgres. And I suspect Postgres will be a better fit with Django.
>>
>> However, I'm not sure what you mean exactly by adjusting fields. Your
>> last question above indicates you want to change the schema in an existing
>> Django project. You need to consider when the fields need to be changed in
>> the context of real-world pressures from your production system users. It
>> might need to be sooner rather than later and that may force adjustments
>> prior to the move to Postgres.
>>
>> If there are problems with the existing MySQL system it would be best to
>> fix them before switching.
>>
>> The bottom line is that preparations and testing for the move has to
>> happen in parallel with ongoing support and maintenance and possibly
>> ongoing development of the production system. When you are ready to switch
>> and happy that it will go like clockwork the actual switch can be scheduled
>> as a definable task in the ongoing workflow. All developers will have to
>> switch at the same time - or prior if they can have access to your
>> completed scripts for their personal development databases.
>>
>> hth
>>
>> Mike
>>
>>
>>> On Thu, Apr 12, 2018 at 6:42 AM, Mike Dewhirst <mi...@dewhirst.com.au
>>> <mailto:mi...@dewhirst.com.au>> wrote:
>>>
>>> On 11/04/2018 11:40 PM, tango ward wrote:
>>>
>>> Hi there,
>>>
>>> This will be my first time to migrate a database in my first
>>> programming job. I checked the dump file today and load it in
>>> MySQL benchmark to view the ERD. The database that I need to
>>> migrate has 48 tables and has existing data already.
>>>
>>>
>>> I would like to know what are the things that I need to do
>>> first. I'm gonna test the migration first in my local machine
>>> before bringing it to live production. I am currently reading
>>> https://wiki.postgresql.org/wiki/Converting_from_other_Datab
>>> ases_to_PostgreSQL
>>> <https://wiki.postgresql.org/wiki/Converting_from_other_Data
>>> bases_to_PostgreSQL>.
>>>
>>>
>>>
>>>
>>> Any suggestions will be highly appreciated.
>>>
>>>
>>> 1. Do the migration locally
>>>
>>> 2. Devise some repeatable automated success tests to prove the
>>> migration works
>>>
>>> 3. Set up a new VM as an exact duplicate production machine
>>> running MySQL. Use your hosts file to put its IP address somewhere
>>> else than the DNS points to. Beware that ACLs often use IP
>>> addresses rather than host names.
>>>
>>> 4. Do the migrations and run the tests on the duplicate machine.
&g

Re: Tips On Migrating DB from other website to django with Postgresql

2018-04-11 Thread tango ward
At the moment, I am comparing the fields from the dump file and the fields
in our models.py. There are fields that exist on the dump file that are not
yet in our existing model/models that why I want to know if should I modify
the schema of our database to match the dump file of the client. I'm lost
on this, sorry.

On Thu, Apr 12, 2018 at 8:46 AM, Mike Dewhirst <mi...@dewhirst.com.au>
wrote:

> On 12/04/2018 9:47 AM, tango ward wrote:
>
>> Hi Mike,
>>
>>
>> Thanks for the advice.
>>
>> May I ask as well, on Django side, since we have already an existing
>> system, how should I adjust the fields that are existing from the dump file
>> to the Django? Should I just add fields in models.py?
>>
>
> Treat that as a separate task. You can do it before the migration or
> after. I would preferdo it afterwards because I am more comfortable with
> Postgres. And I suspect Postgres will be a better fit with Django.
>
> However, I'm not sure what you mean exactly by adjusting fields. Your last
> question above indicates you want to change the schema in an existing
> Django project. You need to consider when the fields need to be changed in
> the context of real-world pressures from your production system users. It
> might need to be sooner rather than later and that may force adjustments
> prior to the move to Postgres.
>
> If there are problems with the existing MySQL system it would be best to
> fix them before switching.
>
> The bottom line is that preparations and testing for the move has to
> happen in parallel with ongoing support and maintenance and possibly
> ongoing development of the production system. When you are ready to switch
> and happy that it will go like clockwork the actual switch can be scheduled
> as a definable task in the ongoing workflow. All developers will have to
> switch at the same time - or prior if they can have access to your
> completed scripts for their personal development databases.
>
> hth
>
> Mike
>
>
>> On Thu, Apr 12, 2018 at 6:42 AM, Mike Dewhirst <mi...@dewhirst.com.au
>> <mailto:mi...@dewhirst.com.au>> wrote:
>>
>> On 11/04/2018 11:40 PM, tango ward wrote:
>>
>> Hi there,
>>
>> This will be my first time to migrate a database in my first
>> programming job. I checked the dump file today and load it in
>> MySQL benchmark to view the ERD. The database that I need to
>> migrate has 48 tables and has existing data already.
>>
>>
>> I would like to know what are the things that I need to do
>> first. I'm gonna test the migration first in my local machine
>> before bringing it to live production. I am currently reading
>> https://wiki.postgresql.org/wiki/Converting_from_other_Datab
>> ases_to_PostgreSQL
>> <https://wiki.postgresql.org/wiki/Converting_from_other_Data
>> bases_to_PostgreSQL>.
>>
>>
>>
>>
>> Any suggestions will be highly appreciated.
>>
>>
>> 1. Do the migration locally
>>
>> 2. Devise some repeatable automated success tests to prove the
>> migration works
>>
>> 3. Set up a new VM as an exact duplicate production machine
>> running MySQL. Use your hosts file to put its IP address somewhere
>> else than the DNS points to. Beware that ACLs often use IP
>> addresses rather than host names.
>>
>> 4. Do the migrations and run the tests on the duplicate machine.
>> Debug as necessary.
>>
>> 5. Announce to users that the system is going down for planned
>> maintenance
>>
>> 6. Remove your hosts file adjustment so your system is back to
>> looking at the real production machine
>>
>> 7. Take production off-line and do a pre-migration dump or backup
>> from which you can restore if things go wrong
>>
>> 8. Do the migration, run the tests then restore service
>>
>> I have done such things in the distant past but not recently. I
>> may have forgotten something but in my opinion items 5 and 7 above
>> are super critical.
>>
>> Good luck
>>
>> Mike
>>
>>
>>
>> Thanks,
>> J
>> -- 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 django-users+unsubscr...@googlegroups.com
>> <mailto:django-users%2bunsubscr...@goog

Tips On Migrating DB from other website to django with Postgresql

2018-04-11 Thread tango ward
Hi there,

This will be my first time to migrate a database in my first programming
job. I checked the dump file today and load it in MySQL benchmark to view
the ERD. The database that I need to migrate has 48 tables and has existing
data already.


I would like to know what are the things that I need to do first. I'm gonna
test the migration first in my local machine before bringing it to live
production. I am currently reading
https://wiki.postgresql.org/wiki/Converting_from_other_Databases_to_PostgreSQL
.


Any suggestions will be highly appreciated.


Thanks,
J

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLKcf22aXXKd6xUn%3DT6HOxHLBN7u1xcn%3DOXO3DdL%3D54XSg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Request Timed Out When Generating Huge Data

2018-04-02 Thread tango ward
I tried loading the site locally to see how long will it take to load a
record of 1800 students. It took about a minute and a half locally. The
request timed out problem occurs when I try to generate a CSV report and
PDF. Both result to timed out even locally.

On Tue, Apr 3, 2018 at 8:12 AM, tango ward <tangowar...@gmail.com> wrote:

> Hi,
>
> SLR.
>
> At the moment, the largest number of students we have is 2000 in one
> campus. I haven't played around with the code but when I check it we're
> using a get_queryset function to get the data and filter it using Q. Then
> display it using get_context_data
>
> Code:
>
> class FinancialReportView(ApplicantReportMixin, ListView):
> template_name = 'education/dashboard/reports/financial_report.html'
> paginate_by = 50
>
> def get_queryset(self):
>
> student_filter = self.request.GET.get('student_filter', '')
>
> filter_date = self.request.GET.get('date', '')
> if not filter_date and not student_filter:
> return Recipient.objects.none()
>
> if student_filter in ['None', None]:
> student_filter = ''
> recipients = self.get_recipients()
> recipients = recipients.filter(enrolled=1)
> recipients = recipients.filter(enrollmentinfo__isnull=False)
>
> campus = self.request.GET.get('campus', '')
> if campus:
> recipients = recipients.filter(department__school=campus)
> year_level = self.request.GET.get('year_level', '')
>
> if year_level:
> recipients = recipients.filter(year_level=year_level)
>
> if student_filter and not student_filter == 'None':
> recipients = recipients.filter(
> Q(first_name__icontains=student_filter) |
> Q(last_name__icontains=student_filter) |
> Q(student_id__icontains=student_filter))
> recipients = recipients.select_related('department', 'program')
> return recipients
>
> def get_context_data(self, **kwargs):
> context = super(FinancialReportView, self).get_context_data(**
> kwargs)
>
> filter_form = FinancialReportFilterForm(
> data=self.request.GET,
> school_manager=self.request.user.schoolmanager,
> )
> output = []
> recipients = self.get_queryset()
>
> filter_date = self.request.GET.get('date', '')
> if filter_date in ['None', None]:
> filter_date = ''
> if filter_date:
> filter_date = dateutil.parser.parse(filter_date).date()
> page = self.request.GET.get('page', 1)
>
> for ctr, recipient in enumerate(recipients):
> total_amount = 0
> enrollment_info = recipient.get_current_enrollment_info()
> if enrollment_info:
> if filter_date:
> invoices = enrollment_info.
> philsmileinvoice_set.filter(
> due_date__lte=filter_date)
> else:
> invoices = enrollment_info.philsmileinvoice_set.all()
>
> for invoice in invoices:
> total_amount += invoice.get_remaining_balance()
>
> output.append([ctr, recipient, total_amount])
>
> if self.paginate_by:
> paginator = Paginator(output, self.paginate_by)
> try:
> output = paginator.page(page)
> except PageNotAnInteger:
> output = paginator.page(1)
> except EmptyPage:
> output = paginator.page(paginator.num_pages)
> context.update({
> 'paginator': paginator
> })
>
> context.update({
> 'outputs': output,
> 'form': filter_form,
> 'school_system': self.request.user.
> schoolmanager.school_system,
> })
> return context
>
>
>
>
> On Mon, Apr 2, 2018 at 1:54 PM, Babatunde Akinyanmi <tundeba...@gmail.com>
> wrote:
>
>> Hi,
>> How many records are we talking about? What code are you using to fetch
>> the records? In other words, add more information so that it's easier to
>> troubleshoot
>>
>> On Mon, 2 Apr 2018, 02:27 tango ward, <tangowar...@gmail.com> wrote:
>>
>>>
>>> Good day,
>>>
>>> I need suggestions on how to approach this problem.
>>>
>>> I am working on a task that needs to generate the list students per
>>> school. When the school has larger number of students, I am getting a
>>> request timed out error. I can filter the school per

Re: Request Timed Out When Generating Huge Data

2018-04-02 Thread tango ward
Hi,

SLR.

At the moment, the largest number of students we have is 2000 in one
campus. I haven't played around with the code but when I check it we're
using a get_queryset function to get the data and filter it using Q. Then
display it using get_context_data

Code:

class FinancialReportView(ApplicantReportMixin, ListView):
template_name = 'education/dashboard/reports/financial_report.html'
paginate_by = 50

def get_queryset(self):

student_filter = self.request.GET.get('student_filter', '')

filter_date = self.request.GET.get('date', '')
if not filter_date and not student_filter:
return Recipient.objects.none()

if student_filter in ['None', None]:
student_filter = ''
recipients = self.get_recipients()
recipients = recipients.filter(enrolled=1)
recipients = recipients.filter(enrollmentinfo__isnull=False)

campus = self.request.GET.get('campus', '')
if campus:
recipients = recipients.filter(department__school=campus)
year_level = self.request.GET.get('year_level', '')

if year_level:
recipients = recipients.filter(year_level=year_level)

if student_filter and not student_filter == 'None':
recipients = recipients.filter(
Q(first_name__icontains=student_filter) |
Q(last_name__icontains=student_filter) |
Q(student_id__icontains=student_filter))
recipients = recipients.select_related('department', 'program')
return recipients

def get_context_data(self, **kwargs):
context = super(FinancialReportView,
self).get_context_data(**kwargs)

filter_form = FinancialReportFilterForm(
data=self.request.GET,
school_manager=self.request.user.schoolmanager,
)
output = []
recipients = self.get_queryset()

filter_date = self.request.GET.get('date', '')
if filter_date in ['None', None]:
filter_date = ''
if filter_date:
filter_date = dateutil.parser.parse(filter_date).date()
page = self.request.GET.get('page', 1)

for ctr, recipient in enumerate(recipients):
total_amount = 0
enrollment_info = recipient.get_current_enrollment_info()
if enrollment_info:
if filter_date:
invoices = enrollment_info.philsmileinvoice_set.filter(
due_date__lte=filter_date)
else:
invoices = enrollment_info.philsmileinvoice_set.all()

for invoice in invoices:
total_amount += invoice.get_remaining_balance()

output.append([ctr, recipient, total_amount])

if self.paginate_by:
paginator = Paginator(output, self.paginate_by)
try:
output = paginator.page(page)
except PageNotAnInteger:
output = paginator.page(1)
except EmptyPage:
output = paginator.page(paginator.num_pages)
context.update({
'paginator': paginator
})

context.update({
'outputs': output,
'form': filter_form,
'school_system': self.request.user.schoolmanager.school_system,
})
return context




On Mon, Apr 2, 2018 at 1:54 PM, Babatunde Akinyanmi <tundeba...@gmail.com>
wrote:

> Hi,
> How many records are we talking about? What code are you using to fetch
> the records? In other words, add more information so that it's easier to
> troubleshoot
>
> On Mon, 2 Apr 2018, 02:27 tango ward, <tangowar...@gmail.com> wrote:
>
>>
>> Good day,
>>
>> I need suggestions on how to approach this problem.
>>
>> I am working on a task that needs to generate the list students per
>> school. When the school has larger number of students, I am getting a
>> request timed out error. I can filter the school per campus to lessen the
>> number of students but the performance in displaying the list of students
>> is still taking too long.
>>
>>
>> Thanks,
>> Jarvis
>>
>> --
>> 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 django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/
>> msgid/django-users/CAA6wQLKn98Yq9JrbQQLVncm2pkEUz
>> aCYm_un0zZFMXQC8ewzrg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAA6wQLKn98Yq9JrbQQLVncm2pkEU

Request Timed Out When Generating Huge Data

2018-04-01 Thread tango ward
Good day,

I need suggestions on how to approach this problem.

I am working on a task that needs to generate the list students per school.
When the school has larger number of students, I am getting a request timed
out error. I can filter the school per campus to lessen the number of
students but the performance in displaying the list of students is still
taking too long.


Thanks,
Jarvis

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLKn98Yq9JrbQQLVncm2pkEUzaCYm_un0zZFMXQC8ewzrg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Simple Search Feature

2018-02-24 Thread tango ward
thanks for the suggestions Ken. I just want to ask too if it's safe to
display the list of songs even if the textbox is empty?

On Sun, Feb 25, 2018 at 10:21 AM, Ken Whitesell 
wrote:

> One of the issues is here:
> if request.method == 'GET':
> song_name = request.GET.get('name', "Error")
> songs = self.model.objects.filter(name__icontains=song_name)
> else:
> songs = self.models.all()
> return render(request, self.template_name, {'songs': songs})
>
> When no parameter is passed, request.method is still "GET" - In fact, this
> method should only be called on a get method, making this test irrelevant.
>
> You _could_ change it to look something like this:
> song_name = request.GET.get('name', None)
> if song_name:
> songs = self.model.objects.filter(name__icontains=song_name)
> else:
> songs = self.models.all()
> return render(request, self.template_name, {'songs': songs})
>
> Hope this helps,
>  Ken
>
>
> On Saturday, February 24, 2018 at 8:18:25 PM UTC-5, tangoward15 wrote:
>>
>> Hi,
>>
>> I am playing around on adding a search feature to a website. I am
>> currently encountering a problem when the page should load a list of songs
>> and after typing in a song title in the search box:
>>
>>
>> views.py
>>
>> class SongListView(ListView):
>> model = SongOne
>> context_object_name = 'songs'
>> template_name = 'songs/song_list.html'
>>
>> def get(self, request, *args, **kwargs):
>>
>> if request.method == 'GET':
>> song_name = request.GET.get('name', "Error")
>> songs = self.model.objects.filter(name__icontains=song_name)
>> else:
>> songs = self.models.all()
>> return render(request, self.template_name, {'songs': songs})
>>
>> problem is when I click the search button with the text box empty, I am
>> getting the list of all the song (url: /songs/?name=) but if I just load
>> the page wihout clicking the submit button (url: /songs/), it doesn't give
>> me the list all the songs. The search box works if I type the correct song
>> name as it shows the song title.  Problem is the page should load all the
>> songs before I search a particular song.
>>
>> Any suggestions so I can enhance my code?
>>
>>
>> Thanks,
>> Jarvis
>>
>> --
> 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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/fee7baf6-7dbe-4a33-a281-f7c8600f73cc%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLK03p7hofrCRAGYQsUxo4NuYddTN5e3rmmOdrUSV-uOUQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Simple Search Feature

2018-02-24 Thread tango ward
Hi,

I am playing around on adding a search feature to a website. I am currently
encountering a problem when the page should load a list of songs and after
typing in a song title in the search box:


views.py

class SongListView(ListView):
model = Song
context_object_name = 'songs'
template_name = 'songs/song_list.html'

def get(self, request, *args, **kwargs):

if request.method == 'GET':
song_name = request.GET.get('name', "Error")
songs = self.model.objects.filter(name__icontains=song_name)
else:
songs = self.models.all()
return render(request, self.template_name, {'songs': songs})

problem is when I click the search button with the text box empty, I am
getting the list of all the song (url: /songs/?name=) but if I just load
the page wihout clicking the submit button (url: /songs/), it doesn't give
me the list all the songs. The search box works if I type the correct song
name as it shows the song title.  Problem is the page should load all the
songs before I search a particular song.

Any suggestions so I can enhance my code?


Thanks,
Jarvis

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLJ5bnMzR1etSRY191KL3fWkMpPsvhKnFBKtAuc1iLNKFg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: When to use get_user_model()

2018-02-19 Thread tango ward
Thanks Xavier

On Mon, Feb 19, 2018 at 1:02 PM, Xavier Paniello <pezba...@gmail.com> wrote:

> Hi tangoward15,
>
> Django will use auth.User as the user model in the system, unless you
> change AUTH_USER_MODEL = RegUser in settings.py
>
> Be carefull, to change the user model has some particularities you can
> read in docs (warning section):
> https://docs.djangoproject.com/en/2.0/ref/settings/#auth-user-model
>
> Other option to extend auth.User is a model with a one2one field related
> to auth.User, or a proxy model:
> https://simpleisbetterthancomplex.com/tutorial/2016/07/22/how-to-
> extend-django-user-model.html
>
> Salut!
>
>
> El diumenge, 18 febrer de 2018 15:23:53 UTC+1, tangoward15 va escriure:
>>
>> @Mukul Agrawal,
>>
>> thanks, i'll read this.
>>
>>
>> @Xavier,
>>
>> the model in forms.py, does it mean it will use the RegUser class from
>> the models.py? Sorry, I am confuse.
>>
>> On Sun, Feb 18, 2018 at 9:41 PM, Mukul Agrawal <amuk...@gmail.com> wrote:
>>
>>> The answer on this link can also help you in why and when to use
>>> get_user_model().
>>> https://stackoverflow.com/questions/24629705/django-using-
>>> get-user-model-vs-settings-auth-user-model
>>>
>>>
>>> On Feb 18, 2018 4:11 AM, "tango ward" <tango...@gmail.com> wrote:
>>>
>>>
>>> Hi,
>>>
>>> I am playing around with user registration. I came across a code where
>>> the get_user_model() was assigned to a model in Meta class inside a form. I
>>> was just wondering, what is the benefit of using the get_user_model() as
>>> Model in a form instead of importing a class from models.py then use that
>>> class as model of the form and when should I use it?
>>>
>>> models.py
>>> class RegUser(User):
>>>
>>> def __str__(self):
>>> return self.username
>>>
>>> forms.py
>>>
>>> class UserCreateForm(UserCreationForm):
>>>
>>> class Meta:
>>> fields = ('username', 'password1', 'password2')
>>> model = get_user_model()
>>>
>>>
>>> Thanks,
>>> Jarvis
>>>
>>> --
>>> 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 django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/django-users/CAA6wQL%2Bq1kQ7ukjtE3gV64iu9y2SXdgojZXBF3R4
>>> 6BCuTN0xoA%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CAA6wQL%2Bq1kQ7ukjtE3gV64iu9y2SXdgojZXBF3R46BCuTN0xoA%40mail.gmail.com?utm_medium=email_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>>
>>> --
>>> 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 django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/django-users/CACRd7haky8%2BY7%2BNDHNFV3EbiSxBU4B65CJUSF
>>> 7v3mXb3%3DP8D%2BA%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CACRd7haky8%2BY7%2BNDHNFV3EbiSxBU4B65CJUSF7v3mXb3%3DP8D%2BA%40mail.gmail.com?utm_medium=email_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
> 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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/226fceca-eb59-49c8-9606-b869f0c25feb%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/226fceca-eb59-49c8-9606-b869f0c25feb%40googlegroups.com?utm_medium=email_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLKZoFWbg_67wtA%3DhFpPKu8OKo%3DCWZw-Baq6Wf%3D%2BZoNXcQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: When to use get_user_model()

2018-02-18 Thread tango ward
@Mukul Agrawal,

thanks, i'll read this.


@Xavier,

the model in forms.py, does it mean it will use the RegUser class from the
models.py? Sorry, I am confuse.

On Sun, Feb 18, 2018 at 9:41 PM, Mukul Agrawal <amuku...@gmail.com> wrote:

> The answer on this link can also help you in why and when to use
> get_user_model().
> https://stackoverflow.com/questions/24629705/django-
> using-get-user-model-vs-settings-auth-user-model
>
>
> On Feb 18, 2018 4:11 AM, "tango ward" <tangowar...@gmail.com> wrote:
>
>
> Hi,
>
> I am playing around with user registration. I came across a code where the
> get_user_model() was assigned to a model in Meta class inside a form. I was
> just wondering, what is the benefit of using the get_user_model() as Model
> in a form instead of importing a class from models.py then use that class
> as model of the form and when should I use it?
>
> models.py
> class RegUser(User):
>
> def __str__(self):
> return self.username
>
> forms.py
>
> class UserCreateForm(UserCreationForm):
>
> class Meta:
> fields = ('username', 'password1', 'password2')
> model = get_user_model()
>
>
> Thanks,
> Jarvis
>
> --
> 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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/ms
> gid/django-users/CAA6wQL%2Bq1kQ7ukjtE3gV64iu9y2SXdgojZXBF3R4
> 6BCuTN0xoA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAA6wQL%2Bq1kQ7ukjtE3gV64iu9y2SXdgojZXBF3R46BCuTN0xoA%40mail.gmail.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> 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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CACRd7haky8%2BY7%2BNDHNFV3EbiSxBU4B65CJUSF7v3mX
> b3%3DP8D%2BA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CACRd7haky8%2BY7%2BNDHNFV3EbiSxBU4B65CJUSF7v3mXb3%3DP8D%2BA%40mail.gmail.com?utm_medium=email_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLJDaCw30Rm05pEGOhpUJJt9yGSJ9R7FdnnNopANobY%2B7A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: When to use get_user_model()

2018-02-17 Thread tango ward
I also checked the documentation of it but I am confuse. It says "Instead
of referring to User
<https://docs.djangoproject.com/en/2.0/ref/contrib/auth/#django.contrib.auth.models.User>
directly, you should reference the user model using
django.contrib.auth.get_user_model(). This method will return the currently
active user model – the custom user model if one is specified, or User
<https://docs.djangoproject.com/en/2.0/ref/contrib/auth/#django.contrib.auth.models.User>
otherwise." When it says "currently active user mode" is it the model that
I created in models.py or the one that is currently logged in to the
website? what does "or User otherwise" mean?

My apologies for asking too many questions.

On Sun, Feb 18, 2018 at 6:39 AM, tango ward <tangowar...@gmail.com> wrote:

>
> Hi,
>
> I am playing around with user registration. I came across a code where the
> get_user_model() was assigned to a model in Meta class inside a form. I was
> just wondering, what is the benefit of using the get_user_model() as Model
> in a form instead of importing a class from models.py then use that class
> as model of the form and when should I use it?
>
> models.py
> class RegUser(User):
>
> def __str__(self):
> return self.username
>
> forms.py
>
> class UserCreateForm(UserCreationForm):
>
> class Meta:
> fields = ('username', 'password1', 'password2')
> model = get_user_model()
>
>
> Thanks,
> Jarvis
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQL%2BQuRBqAZpzeyszo719ruvo%3DO7jRPv2EkNAF6oEN6CMKg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


When to use get_user_model()

2018-02-17 Thread tango ward
Hi,

I am playing around with user registration. I came across a code where the
get_user_model() was assigned to a model in Meta class inside a form. I was
just wondering, what is the benefit of using the get_user_model() as Model
in a form instead of importing a class from models.py then use that class
as model of the form and when should I use it?

models.py
class RegUser(User):

def __str__(self):
return self.username

forms.py

class UserCreateForm(UserCreationForm):

class Meta:
fields = ('username', 'password1', 'password2')
model = get_user_model()


Thanks,
Jarvis

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQL%2Bq1kQ7ukjtE3gV64iu9y2SXdgojZXBF3R46BCuTN0xoA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: importError: Count Not import Django inside Virtualenv

2018-02-14 Thread tango ward
that's odd. Whenever I test a pacakge, it's always installed first in
virtualenv. Maybe when I updated my system? Btw, I have some projects which
are not yet in github, can I just copy and paste them in a new folder with
new virtualenv?

On Wed, Feb 14, 2018 at 4:44 PM, PASCUAL Eric <eric.pasc...@cstb.fr> wrote:

> Hi,
>
>
> Hard to say without knowing the exact context, but my gut feeling is that
> you've modified a system wide library at a moment (maybe inadvertently).
>
>
> My own experience is that it's easy to mess with Python libraries when
> installing packages with sudo , which may happen form time to  time
> when working with virtualenv (or pyenv) since not very long, and being
> caught up by old habits (they tend to survive longer that wanted ).
>
>
> Even if far less harmful, then --user option is to avoid for projects
> related libs, for the same reasons.
>
>
> Eric
> --
> *From:* django-users@googlegroups.com <django-users@googlegroups.com> on
> behalf of tango ward <tangowar...@gmail.com>
> *Sent:* Wednesday, February 14, 2018 3:40:04 AM
> *To:* django-users@googlegroups.com
> *Subject:* Re: importError: Count Not import Django inside Virtualenv
>
> Hi Eric,
>
>
> I tried what you suggested and it works! I was just wondering why my
> existing pet projects have the same problem?
>
> On Wed, Feb 14, 2018 at 10:13 AM, tango ward <tangowar...@gmail.com>
> wrote:
>
> Hi,
>
> The error message that I am getting is:
>
> Traceback (most recent call last):
>   File "manage.py", line 8, in 
> from django.core.management import execute_from_command_line
> ModuleNotFoundError: No module named 'django'
>
> The above exception was the direct cause of the following exception:
>
> Traceback (most recent call last):
>   File "manage.py", line 14, in 
> ) from exc
> ImportError: Couldn't import Django. Are you sure it's installed and
> available on your PYTHONPATH environment variable? Did you forget to
> activate a virtual environment?
>
>
> @Jason,
>
> It's weird because couple of days, I can still run these pet projects
> without any error. If I go to venv folder virtual/lib/python3.6/site-packages,
> I can see django there. It seems that even though virtualenv is activated,
> the packages I installed inside it are not recognized by the system.
>
>
> On Wed, Feb 14, 2018 at 5:38 AM, PASCUAL Eric <eric.pasc...@cstb.fr>
> wrote:
>
> Hi Jarvis,
>
>
> Can you provide the error messages trace ? It can greatly help
> understanding what's happening.
>
>
> If you haven't already done this, try to restart from a fresh new
> virtualenv inside which you'll install Django and the additional packages
> you've added (if any). Then restore a copy of your project in this context
> (if by chance you work with git, a simple git clone will do the trick) and
> test your app again.
>
>
> Hoping you haven't already messed your system Python by installing stuff
> in sudo mode. The situation could be a little more complicated then.
>
>
> Best.
>
>
> Eric
> --
> *From:* django-users@googlegroups.com <django-users@googlegroups.com> on
> behalf of tango ward <tangowar...@gmail.com>
> *Sent:* Tuesday, February 13, 2018 9:43:45 PM
> *To:* django-users@googlegroups.com
> *Subject:* importError: Count Not import Django inside Virtualenv
>
> Hi,
>
> I want to seek some advice about the error. All of my pet projects in my
> desktop are getting the same error even though virtualenv is activated. I
> can confirm that when I started playing around with the projects, I have
> installed Django inside virtualenv without using "sudo". Now, I can't run
> python manage.py runserver and the packages that I am getting whenever I
> run pip freeze are different from before which doesn't include Django in
> the list.
>
>
> Any advice pls?
>
>
> Thanks,
> Jarvis
>
> --
> 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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/ms
> gid/django-users/CAA6wQLKp3oz-6FfDzQ%3Dip4XRsuLPSeOCuwkbUuWb
> e1JNx2YhFA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAA6wQLKp3oz-6FfDzQ%3Dip4XRsuLPSeOCuwkbUuWbe1JNx2YhFA%40mail.gmail.com?utm_medium=email_source=footer>

Re: importError: Count Not import Django inside Virtualenv

2018-02-13 Thread tango ward
Hi Eric,


I tried what you suggested and it works! I was just wondering why my
existing pet projects have the same problem?

On Wed, Feb 14, 2018 at 10:13 AM, tango ward <tangowar...@gmail.com> wrote:

> Hi,
>
> The error message that I am getting is:
>
> Traceback (most recent call last):
>   File "manage.py", line 8, in 
> from django.core.management import execute_from_command_line
> ModuleNotFoundError: No module named 'django'
>
> The above exception was the direct cause of the following exception:
>
> Traceback (most recent call last):
>   File "manage.py", line 14, in 
> ) from exc
> ImportError: Couldn't import Django. Are you sure it's installed and
> available on your PYTHONPATH environment variable? Did you forget to
> activate a virtual environment?
>
>
> @Jason,
>
> It's weird because couple of days, I can still run these pet projects
> without any error. If I go to venv folder virtual/lib/python3.6/site-packages,
> I can see django there. It seems that even though virtualenv is activated,
> the packages I installed inside it are not recognized by the system.
>
>
> On Wed, Feb 14, 2018 at 5:38 AM, PASCUAL Eric <eric.pasc...@cstb.fr>
> wrote:
>
>> Hi Jarvis,
>>
>>
>> Can you provide the error messages trace ? It can greatly help
>> understanding what's happening.
>>
>>
>> If you haven't already done this, try to restart from a fresh new
>> virtualenv inside which you'll install Django and the additional packages
>> you've added (if any). Then restore a copy of your project in this context
>> (if by chance you work with git, a simple git clone will do the trick) and
>> test your app again.
>>
>>
>> Hoping you haven't already messed your system Python by installing stuff
>> in sudo mode. The situation could be a little more complicated then.
>>
>>
>> Best.
>>
>>
>> Eric
>> --
>> *From:* django-users@googlegroups.com <django-users@googlegroups.com> on
>> behalf of tango ward <tangowar...@gmail.com>
>> *Sent:* Tuesday, February 13, 2018 9:43:45 PM
>> *To:* django-users@googlegroups.com
>> *Subject:* importError: Count Not import Django inside Virtualenv
>>
>> Hi,
>>
>> I want to seek some advice about the error. All of my pet projects in my
>> desktop are getting the same error even though virtualenv is activated. I
>> can confirm that when I started playing around with the projects, I have
>> installed Django inside virtualenv without using "sudo". Now, I can't run
>> python manage.py runserver and the packages that I am getting whenever I
>> run pip freeze are different from before which doesn't include Django in
>> the list.
>>
>>
>> Any advice pls?
>>
>>
>> Thanks,
>> Jarvis
>>
>> --
>> 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 django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/CAA6wQLKp3oz-6FfDzQ%3Dip4XRsuLPSeOCuwkbUuWb
>> e1JNx2YhFA%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAA6wQLKp3oz-6FfDzQ%3Dip4XRsuLPSeOCuwkbUuWbe1JNx2YhFA%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> 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 django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/AM5P193MB0083C66FCD689270720750708CF60%
>> 40AM5P193MB0083.EURP193.PROD.OUTLOOK.COM
>> <https://groups.google.com/d/msgid/django-users/AM5P193MB0083C66FCD689270720750708CF60%40AM5P193MB0083.EURP193.PROD.OUTLOOK.COM?utm_medium=email_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLJCkd0B-0ep8jrUFk1QUp%3D_jQ_AuundhzBMwOSYf7h4fg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: importError: Count Not import Django inside Virtualenv

2018-02-13 Thread tango ward
Hi,

The error message that I am getting is:

Traceback (most recent call last):
  File "manage.py", line 8, in 
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 14, in 
) from exc
ImportError: Couldn't import Django. Are you sure it's installed and
available on your PYTHONPATH environment variable? Did you forget to
activate a virtual environment?


@Jason,

It's weird because couple of days, I can still run these pet projects
without any error. If I go to venv folder
virtual/lib/python3.6/site-packages, I can see django there. It seems that
even though virtualenv is activated, the packages I installed inside it are
not recognized by the system.


On Wed, Feb 14, 2018 at 5:38 AM, PASCUAL Eric <eric.pasc...@cstb.fr> wrote:

> Hi Jarvis,
>
>
> Can you provide the error messages trace ? It can greatly help
> understanding what's happening.
>
>
> If you haven't already done this, try to restart from a fresh new
> virtualenv inside which you'll install Django and the additional packages
> you've added (if any). Then restore a copy of your project in this context
> (if by chance you work with git, a simple git clone will do the trick) and
> test your app again.
>
>
> Hoping you haven't already messed your system Python by installing stuff
> in sudo mode. The situation could be a little more complicated then.
>
>
> Best.
>
>
> Eric
> ------
> *From:* django-users@googlegroups.com <django-users@googlegroups.com> on
> behalf of tango ward <tangowar...@gmail.com>
> *Sent:* Tuesday, February 13, 2018 9:43:45 PM
> *To:* django-users@googlegroups.com
> *Subject:* importError: Count Not import Django inside Virtualenv
>
> Hi,
>
> I want to seek some advice about the error. All of my pet projects in my
> desktop are getting the same error even though virtualenv is activated. I
> can confirm that when I started playing around with the projects, I have
> installed Django inside virtualenv without using "sudo". Now, I can't run
> python manage.py runserver and the packages that I am getting whenever I
> run pip freeze are different from before which doesn't include Django in
> the list.
>
>
> Any advice pls?
>
>
> Thanks,
> Jarvis
>
> --
> 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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAA6wQLKp3oz-6FfDzQ%3Dip4XRsuLPSeOCuwkbUuWbe1JNx2Y
> hFA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAA6wQLKp3oz-6FfDzQ%3Dip4XRsuLPSeOCuwkbUuWbe1JNx2YhFA%40mail.gmail.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
> --
> 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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/AM5P193MB0083C66FCD689270720750708CF60%40AM5P193MB0083.
> EURP193.PROD.OUTLOOK.COM
> <https://groups.google.com/d/msgid/django-users/AM5P193MB0083C66FCD689270720750708CF60%40AM5P193MB0083.EURP193.PROD.OUTLOOK.COM?utm_medium=email_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLLZyeuQiFL6fe4HvC4a6ogZnTh7kGrc62ni95aPggChyA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


importError: Count Not import Django inside Virtualenv

2018-02-13 Thread tango ward
Hi,

I want to seek some advice about the error. All of my pet projects in my
desktop are getting the same error even though virtualenv is activated. I
can confirm that when I started playing around with the projects, I have
installed Django inside virtualenv without using "sudo". Now, I can't run
python manage.py runserver and the packages that I am getting whenever I
run pip freeze are different from before which doesn't include Django in
the list.


Any advice pls?


Thanks,
Jarvis

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLKp3oz-6FfDzQ%3Dip4XRsuLPSeOCuwkbUuWbe1JNx2YhFA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: wsgi error

2018-01-31 Thread tango ward
Hi, thanks for the response. I was able to solved it. Turns out that my
should be in the same directory with manage.py.

On Tue, Jan 30, 2018 at 2:01 PM, Matemática A3K <matematica@gmail.com>
wrote:

>
>
> On Sat, Jan 27, 2018 at 12:05 AM, tango ward <tangowar...@gmail.com>
> wrote:
>
>> Hi Team,
>>
>> Not sure if this issue covered here but I am getting an error uploading
>> my pet project in Heroku.
>>
>> ModuleNotFoundError: No module named 'animals.wsgi'
>>
>> 2018-01-27T02:59:26.637953+00:00 app[web.1]: [2018-01-27 02:59:26 +] [8] 
>> [INFO] Worker exiting (pid: 8)
>>
>> 2018-01-27T02:59:26.669632+00:00 app[web.1]: [2018-01-27 02:59:26 +] [4] 
>> [INFO] Shutting down: Master
>>
>> 2018-01-27T02:59:26.669770+00:00 app[web.1]: [2018-01-27 02:59:26 +] [4] 
>> [INFO] Reason: Worker failed to boot.
>>
>>
>>
>> my Procfile in my root folder contains this:
>>
>> web: gunicorn animals.wsgi:application --log-file - --log-level debug
>>
>> where animals is the name of my project, where my wsgi.py file is
>> residing.
>>
>> I tried searching this in StackOverflow but most of the answers are
>> saying that it must be "web: gunicorn PROJECT_NAME.wsgi:application
>> --log-file - --log-level debug" which I already did in my Procfile.
>>
>>
>> Any suggestions?
>>
>>
> This is more a Heroku question, you should seek help in their docs, forums
> / communication channels.
>
> AFAIK, a Procfile with "web: gunicorn animals.wsgi" should be enough and
> work.
>
> HTH!
>
>
>>
>>
>> Regards,
>> Jarvis
>>
>> --
>> 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 django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/CAA6wQLKi4vjKpVByRykvkXoPkpPUBprVq2pvmn-Oab
>> zSkAFoyQ%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAA6wQLKi4vjKpVByRykvkXoPkpPUBprVq2pvmn-OabzSkAFoyQ%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> 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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CA%2BFDnhLr9p%3DHnCj-L0u3MXU3VGbwoLE3wNH2uCgZX7c2wq
> sD-w%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CA%2BFDnhLr9p%3DHnCj-L0u3MXU3VGbwoLE3wNH2uCgZX7c2wqsD-w%40mail.gmail.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLKOd6O1SqzpsZh-RgE%2Buvgy1hHUW2D%2BXJNFdhAXN6xMBw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: CRUD code feedback

2018-01-28 Thread tango ward
   form.instance.owner =
>>>>> self.request.user    return super(CreateDog, self).form_valid(form)*
>>>>>
>>>>>
>>>>> On Sunday, 28 January 2018 19:32:35 UTC+5:30, Akhil Lawrence wrote:
>>>>>>
>>>>>> This error message is tricky.
>>>>>>
>>>>>> According to your model definition *owner* is of type *Owner*. This
>>>>>> error message actually comes from the *Owner* model.
>>>>>>
>>>>>> Instead of  *form.instance.owner = self.request.user*, try  
>>>>>> *form.instance.owner
>>>>>> = Owner(id=self.request.user.id <http://self.request.user.id>)*
>>>>>>
>>>>>> It should work.
>>>>>>
>>>>>> On Sunday, 28 January 2018 18:37:08 UTC+5:30, tangoward15 wrote:
>>>>>>>
>>>>>>> Sorry, for asking again. In option one, It appears that I am getting
>>>>>>> an error for using the owner field which is a ForeignKey.
>>>>>>>
>>>>>>> "
>>>>>>>
>>>>>>> ">": "Dog.owner" must be a "User" 
>>>>>>> instance."
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> class CreateDog(CreateView):
>>>>>>> template_name = 'dogs_cats/create_dog.html'
>>>>>>> model = Dog
>>>>>>> fields = ('name', 'bday')
>>>>>>>
>>>>>>> def form_valid(self, form):
>>>>>>> form.instance.owner = self.request.user
>>>>>>> return super(CreateDog, self).form_valid(form)
>>>>>>>
>>>>>>>
>>>>>>> I looked at StackOverflow and saw this thread
>>>>>>> https://stackoverflow.com/questions/30017334/django-foreign-
>>>>>>> key-must-be-an-instance. Is there a way to use the same solution in
>>>>>>> side the form_valid()?
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Sun, Jan 28, 2018 at 5:32 PM, tango ward <tango...@gmail.com>
>>>>>>> wrote:
>>>>>>>
>>>>>>>> Thanks, I'm digesting it. I am going to use the first option.
>>>>>>>>
>>>>>>>> On Sun, Jan 28, 2018 at 3:20 PM, Akhil Lawrence <
>>>>>>>> akhilp...@gmail.com> wrote:
>>>>>>>>
>>>>>>>>> I doubt whether you are reading my response properly. Let me
>>>>>>>>> reiterate my response for you.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> *There are two ways to do this. *
>>>>>>>>>
>>>>>>>>> *1. You can set the owner as the logged in user by default*
>>>>>>>>> *2. You can provide all possible owners as options and the user
>>>>>>>>> can select the owner from a dropdown.*
>>>>>>>>>
>>>>>>>>> *For case 1, you may not want to display the owner field in
>>>>>>>>> frontend. Here you can override form_valid and set the owner as 
>>>>>>>>> logged in
>>>>>>>>> user.*
>>>>>>>>>
>>>>>>>>> *class CreateDog(CreateView):*
>>>>>>>>> *...*
>>>>>>>>> *def form_valid(self, form):*
>>>>>>>>> *form.instance.owner = self.request.user*
>>>>>>>>> *return super(CreateDog, self).form_valid(form)*
>>>>>>>>>
>>>>>>>>> *For more details:*
>>>>>>>>>
>>>>>>>>> *https://docs.djangoproject.com/en/2.0/topics/class-based-views/generic-editing/#models-and-request-user
>>>>>>>>> <https://docs.djangoproject.com/en/2.0/topics/class-based-views/generic-editing/#models-and-request-user>*
>>>>>>>>>
>>>>>>>>> *http://ccbv.co.uk/projects/Django/1.11/django.views.generic.edit/CreateView/#form_valid
>>>>>>>>> <http://ccbv.co.uk/projects/Django/1.11/django.views.generic.edit/CreateView/#form_valid>*
>>>>>>>&g

Re: CRUD code feedback

2018-01-28 Thread tango ward
Holy smoke it's working!!!

Thanks a lot!

I can use the same pattern for update and delete right?

On Sun, Jan 28, 2018 at 10:59 PM, Akhil Lawrence <akhilputh...@gmail.com>
wrote:

> The takeaway from the above error is *AnonymousUser*
>
>
> This means you are not logged into the system. By default *self.request.user* 
> will be an instance of *AnonymousUser*,
>
> the moment you login it becomes *User* instance
>
>
> Make sure you login before hitting this code
>
>
> Thanks.
>
>
> On Sunday, 28 January 2018 20:10:38 UTC+5:30, tangoward15 wrote:
>
>> I am getting another error:
>>
>> Cannot assign "> object at 0x7fe3fa28fe48>>": "Dog.owner" must be a "User" instance.
>>
>> models.py
>>
>> from django.db import models
>> from django.contrib.auth import get_user_model
>> from django.contrib.auth.models import User, PermissionsMixin
>> from django.urls import reverse
>>
>>
>> # Create your models here.
>>
>>
>> class RegUser(User, PermissionsMixin):
>>
>> def __str__(self):
>> return "@{}".format(self.username)
>>
>>
>> class Dog(models.Model):
>> name = models.CharField(max_length=40)
>> bday = models.DateField()
>> owner = models.ForeignKey(User, related_name='dogs',
>> on_delete=models.CASCADE)
>>
>> def __str__(self):
>> return self.name
>>
>>
>> views.py
>>
>>
>> class CreateDog(CreateView):
>> template_name = 'dogs_cats/create_dog.html'
>> model = Dog
>> fields = ('name', 'bday')
>>
>> def form_valid(self, form):
>> form.instance.owner = self.request.user
>> return supter(CreateDog, self).form_valid(form)
>>
>> On Sun, Jan 28, 2018 at 10:20 PM, Akhil Lawrence <akhilp...@gmail.com>
>> wrote:
>>
>>> Oops I missed something, you are creating a different table all together
>>> for *Owner*. In that case you need to insert owner record (This is not
>>> recommended, since the data is going to be the exact copy of User. This
>>> will cause data inconsistency, use User instead)
>>>
>>> class CreateDog(CreateView):
>>> template_name = 'dogs_cats/create_dog.html'
>>> model = Dog
>>> fields = ('name', 'bday')
>>>
>>>
>>> def form_valid(self, form):
>>> *owner = Owner.objects.create_user(self.request.user.username,
>>> self.request.user.email, self.request.user.password)*
>>> *form.instance.owner = owner*
>>> return super(CreateDog, self).form_valid(form)
>>>
>>> But I would say this approach is wrong, your *Owner* is exact copy of
>>> *User*. Use *User* instead.
>>>
>>> The ideal way should be,
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> *class Cat(models.Model):name = models.CharField(max_length=40)
>>> bday = models.DateField()owner = models.ForeignKey(User,
>>> related_name='cats', on_delete=models.CASCADE)*
>>>
>>>
>>>
>>> *class CreateDog(CreateView):template_name =
>>> 'dogs_cats/create_dog.html'model = Dog*
>>> *fields = ('name', 'bday')*
>>>
>>>
>>>
>>> *def form_valid(self, form):form.instance.owner =
>>> self.request.userreturn super(CreateDog, self).form_valid(form)*
>>>
>>>
>>> On Sunday, 28 January 2018 19:32:35 UTC+5:30, Akhil Lawrence wrote:
>>>>
>>>> This error message is tricky.
>>>>
>>>> According to your model definition *owner* is of type *Owner*. This
>>>> error message actually comes from the *Owner* model.
>>>>
>>>> Instead of  *form.instance.owner = self.request.user*, try  
>>>> *form.instance.owner
>>>> = Owner(id=self.request.user.id <http://self.request.user.id>)*
>>>>
>>>> It should work.
>>>>
>>>> On Sunday, 28 January 2018 18:37:08 UTC+5:30, tangoward15 wrote:
>>>>>
>>>>> Sorry, for asking again. In option one, It appears that I am getting
>>>>> an error for using the owner field which is a ForeignKey.
>>>>>
>>>>> "
>>>>>
>>>>> ">": "Dog.owner" must be a "User" 
>>>>> instance."
>>>>>
>>>>>
>>>>>
>&g

Re: CRUD code feedback

2018-01-28 Thread tango ward
I am getting another error:

Cannot assign ">":
"Dog.owner" must be a "User" instance.

models.py

from django.db import models
from django.contrib.auth import get_user_model
from django.contrib.auth.models import User, PermissionsMixin
from django.urls import reverse


# Create your models here.


class RegUser(User, PermissionsMixin):

def __str__(self):
return "@{}".format(self.username)


class Dog(models.Model):
name = models.CharField(max_length=40)
bday = models.DateField()
owner = models.ForeignKey(User, related_name='dogs',
on_delete=models.CASCADE)

def __str__(self):
return self.name


views.py


class CreateDog(CreateView):
template_name = 'dogs_cats/create_dog.html'
model = Dog
fields = ('name', 'bday')

def form_valid(self, form):
form.instance.owner = self.request.user
return supter(CreateDog, self).form_valid(form)

On Sun, Jan 28, 2018 at 10:20 PM, Akhil Lawrence <akhilputh...@gmail.com>
wrote:

> Oops I missed something, you are creating a different table all together
> for *Owner*. In that case you need to insert owner record (This is not
> recommended, since the data is going to be the exact copy of User. This
> will cause data inconsistency, use User instead)
>
> class CreateDog(CreateView):
> template_name = 'dogs_cats/create_dog.html'
> model = Dog
> fields = ('name', 'bday')
>
>
> def form_valid(self, form):
> *owner = Owner.objects.create_user(self.request.user.username,
> self.request.user.email, self.request.user.password)*
> *form.instance.owner = owner*
> return super(CreateDog, self).form_valid(form)
>
> But I would say this approach is wrong, your *Owner* is exact copy of
> *User*. Use *User* instead.
>
> The ideal way should be,
>
>
>
>
>
>
>
> *class Cat(models.Model):name = models.CharField(max_length=40)
> bday = models.DateField()owner = models.ForeignKey(User,
> related_name='cats', on_delete=models.CASCADE)*
>
>
>
> *class CreateDog(CreateView):template_name =
> 'dogs_cats/create_dog.html'model = Dog*
> *fields = ('name', 'bday')*
>
>
>
> *def form_valid(self, form):form.instance.owner =
> self.request.userreturn super(CreateDog, self).form_valid(form)*
>
>
> On Sunday, 28 January 2018 19:32:35 UTC+5:30, Akhil Lawrence wrote:
>>
>> This error message is tricky.
>>
>> According to your model definition *owner* is of type *Owner*. This
>> error message actually comes from the *Owner* model.
>>
>> Instead of  *form.instance.owner = self.request.user*, try  
>> *form.instance.owner
>> = Owner(id=self.request.user.id <http://self.request.user.id>)*
>>
>> It should work.
>>
>> On Sunday, 28 January 2018 18:37:08 UTC+5:30, tangoward15 wrote:
>>>
>>> Sorry, for asking again. In option one, It appears that I am getting an
>>> error for using the owner field which is a ForeignKey.
>>>
>>> "
>>>
>>> ">": "Dog.owner" must be a "User" 
>>> instance."
>>>
>>>
>>>
>>> class CreateDog(CreateView):
>>> template_name = 'dogs_cats/create_dog.html'
>>> model = Dog
>>> fields = ('name', 'bday')
>>>
>>> def form_valid(self, form):
>>> form.instance.owner = self.request.user
>>> return super(CreateDog, self).form_valid(form)
>>>
>>>
>>> I looked at StackOverflow and saw this thread
>>> https://stackoverflow.com/questions/30017334/django-foreign-
>>> key-must-be-an-instance. Is there a way to use the same solution in
>>> side the form_valid()?
>>>
>>>
>>>
>>> On Sun, Jan 28, 2018 at 5:32 PM, tango ward <tango...@gmail.com> wrote:
>>>
>>>> Thanks, I'm digesting it. I am going to use the first option.
>>>>
>>>> On Sun, Jan 28, 2018 at 3:20 PM, Akhil Lawrence <akhilp...@gmail.com>
>>>> wrote:
>>>>
>>>>> I doubt whether you are reading my response properly. Let me reiterate
>>>>> my response for you.
>>>>>
>>>>>
>>>>> *There are two ways to do this. *
>>>>>
>>>>> *1. You can set the owner as the logged in user by default*
>>>>> *2. You can provide all possible owners as options and the user can
>>>>> select the owner from a dropdown.*
>>>>>
>>>>> *For case 1, you may not want to display the owner field in frontend.
&

Re: CRUD code feedback

2018-01-28 Thread tango ward
Now I am getting this error

"save() prohibited to prevent data loss due to unsaved related object
'owner'."


Really appreciate you're help/suggestions. My first time to mess
around with CRUD with user registration, login, logout.


On Sun, Jan 28, 2018 at 10:02 PM, Akhil Lawrence <akhilputh...@gmail.com>
wrote:

> This error message is tricky.
>
> According to your model definition *owner* is of type *Owner*. This error
> message actually comes from the *Owner* model.
>
> Instead of  *form.instance.owner = self.request.user*, try  
> *form.instance.owner
> = Owner(id=self.request.user.id <http://self.request.user.id>)*
>
> It should work.
>
> On Sunday, 28 January 2018 18:37:08 UTC+5:30, tangoward15 wrote:
>>
>> Sorry, for asking again. In option one, It appears that I am getting an
>> error for using the owner field which is a ForeignKey.
>>
>> "
>>
>> ">": "Dog.owner" must be a "User" instance."
>>
>>
>>
>> class CreateDog(CreateView):
>> template_name = 'dogs_cats/create_dog.html'
>> model = Dog
>> fields = ('name', 'bday')
>>
>> def form_valid(self, form):
>> form.instance.owner = self.request.user
>> return super(CreateDog, self).form_valid(form)
>>
>>
>> I looked at StackOverflow and saw this thread
>> https://stackoverflow.com/questions/30017334/django-foreign-
>> key-must-be-an-instance. Is there a way to use the same solution in side
>> the form_valid()?
>>
>>
>>
>> On Sun, Jan 28, 2018 at 5:32 PM, tango ward <tango...@gmail.com> wrote:
>>
>>> Thanks, I'm digesting it. I am going to use the first option.
>>>
>>> On Sun, Jan 28, 2018 at 3:20 PM, Akhil Lawrence <akhilp...@gmail.com>
>>> wrote:
>>>
>>>> I doubt whether you are reading my response properly. Let me reiterate
>>>> my response for you.
>>>>
>>>>
>>>> *There are two ways to do this. *
>>>>
>>>> *1. You can set the owner as the logged in user by default*
>>>> *2. You can provide all possible owners as options and the user can
>>>> select the owner from a dropdown.*
>>>>
>>>> *For case 1, you may not want to display the owner field in frontend.
>>>> Here you can override form_valid and set the owner as logged in user.*
>>>>
>>>> *class CreateDog(CreateView):*
>>>> *...*
>>>> *def form_valid(self, form):*
>>>> *form.instance.owner = self.request.user*
>>>> *return super(CreateDog, self).form_valid(form)*
>>>>
>>>> *For more details:*
>>>>
>>>> *https://docs.djangoproject.com/en/2.0/topics/class-based-views/generic-editing/#models-and-request-user
>>>> <https://docs.djangoproject.com/en/2.0/topics/class-based-views/generic-editing/#models-and-request-user>*
>>>>
>>>> *http://ccbv.co.uk/projects/Django/1.11/django.views.generic.edit/CreateView/#form_valid
>>>> <http://ccbv.co.uk/projects/Django/1.11/django.views.generic.edit/CreateView/#form_valid>*
>>>>
>>>>
>>>> *For case 2, you need to populate the list of owners by overriding the
>>>> get_initial method.*
>>>>
>>>> *class CreateDog(CreateView):*
>>>> *...*
>>>> *def get_initial(self):*
>>>> *initial_data = super(CreateDog, self).get_initial()*
>>>> *initial_data["owner"] = [(x.id <http://x.id/>, x.name
>>>> <http://x.name/>) for x in Owner.objects.all()]*
>>>> *return initial_data*
>>>>
>>>> *For more details:*
>>>>
>>>> *https://docs.djangoproject.com/en/2.0/ref/class-based-views/mixins-editing/#django.views.generic.edit.FormMixin.initial
>>>> <https://docs.djangoproject.com/en/2.0/ref/class-based-views/mixins-editing/#django.views.generic.edit.FormMixin.initial>*
>>>>
>>>> *http://ccbv.co.uk/projects/Django/1.11/django.views.generic.edit/CreateView/#get_initial*
>>>> <http://ccbv.co.uk/projects/Django/1.11/django.views.generic.edit/CreateView/#get_initial>
>>>>
>>>>
>>>> if you don't want to show the owner and want to associate the pet with
>>>> owner via backend go for option1 (also note that you may need to remove the
>>>> owner from fields of your createview)
>>>> if you want to show a dropdown of poss

Re: CRUD code feedback

2018-01-28 Thread tango ward
Sorry, for asking again. In option one, It appears that I am getting an
error for using the owner field which is a ForeignKey.

"

">": "Dog.owner" must be a "User" instance."



class CreateDog(CreateView):
template_name = 'dogs_cats/create_dog.html'
model = Dog
fields = ('name', 'bday')

def form_valid(self, form):
form.instance.owner = self.request.user
return super(CreateDog, self).form_valid(form)


I looked at StackOverflow and saw this thread
https://stackoverflow.com/questions/30017334/django-foreign-key-must-be-an-instance.
Is there a way to use the same solution in side the form_valid()?



On Sun, Jan 28, 2018 at 5:32 PM, tango ward <tangowar...@gmail.com> wrote:

> Thanks, I'm digesting it. I am going to use the first option.
>
> On Sun, Jan 28, 2018 at 3:20 PM, Akhil Lawrence <akhilputh...@gmail.com>
> wrote:
>
>> I doubt whether you are reading my response properly. Let me reiterate my
>> response for you.
>>
>>
>> *There are two ways to do this. *
>>
>> *1. You can set the owner as the logged in user by default*
>> *2. You can provide all possible owners as options and the user can
>> select the owner from a dropdown.*
>>
>> *For case 1, you may not want to display the owner field in frontend.
>> Here you can override form_valid and set the owner as logged in user.*
>>
>> *class CreateDog(CreateView):*
>> *...*
>> *def form_valid(self, form):*
>> *form.instance.owner = self.request.user*
>> *return super(CreateDog, self).form_valid(form)*
>>
>> *For more details:*
>>
>> *https://docs.djangoproject.com/en/2.0/topics/class-based-views/generic-editing/#models-and-request-user
>> <https://docs.djangoproject.com/en/2.0/topics/class-based-views/generic-editing/#models-and-request-user>*
>>
>> *http://ccbv.co.uk/projects/Django/1.11/django.views.generic.edit/CreateView/#form_valid
>> <http://ccbv.co.uk/projects/Django/1.11/django.views.generic.edit/CreateView/#form_valid>*
>>
>>
>> *For case 2, you need to populate the list of owners by overriding the
>> get_initial method.*
>>
>> *class CreateDog(CreateView):*
>> *...*
>> *def get_initial(self):*
>> *initial_data = super(CreateDog, self).get_initial()*
>> *initial_data["owner"] = [(x.id <http://x.id/>, x.name
>> <http://x.name/>) for x in Owner.objects.all()]*
>> *return initial_data*
>>
>> *For more details:*
>>
>> *https://docs.djangoproject.com/en/2.0/ref/class-based-views/mixins-editing/#django.views.generic.edit.FormMixin.initial
>> <https://docs.djangoproject.com/en/2.0/ref/class-based-views/mixins-editing/#django.views.generic.edit.FormMixin.initial>*
>>
>> *http://ccbv.co.uk/projects/Django/1.11/django.views.generic.edit/CreateView/#get_initial*
>> <http://ccbv.co.uk/projects/Django/1.11/django.views.generic.edit/CreateView/#get_initial>
>>
>>
>> if you don't want to show the owner and want to associate the pet with
>> owner via backend go for option1 (also note that you may need to remove the
>> owner from fields of your createview)
>> if you want to show a dropdown of possible owners go for option 2.
>>
>> If you need further assistance, please share your screen via chrome
>> remote desktop or something and lets solve it
>>
>> Thanks.
>>
>>
>> On Sunday, 28 January 2018 12:29:58 UTC+5:30, tangoward15 wrote:
>>>
>>> Sorry for being a drag, I tried this code:
>>>
>>> class CreateDog(CreateView):
>>> template_name = 'dogs_cats/create_dog.html'
>>> model = Dog
>>> fields = ('name', 'bday', 'owner')
>>>
>>> def get_initial(self):
>>> initial_data = super(CreateDog, self).get_initial()
>>> initial_data["owner"] = [(self.request.user.id,
>>> self.request.user.username)]
>>> return initial_data
>>>
>>>
>>> still I am getting the Admin user in the drop down list for owner.
>>>
>>> On Sun, Jan 28, 2018 at 2:31 PM, Akhil Lawrence <akhilp...@gmail.com>
>>> wrote:
>>>
>>>>
>>>> override get_initial and set only the logged in user
>>>>
>>>> class CreateDog(CreateView):
>>>> ...
>>>> def get_initial(self):
>>>> initial_data = super(CreateDog, self).get_initial()
>>>> initial_data["owner"] = [(self.request.user.id,
>>

Re: CRUD code feedback

2018-01-28 Thread tango ward
Thanks, I'm digesting it. I am going to use the first option.

On Sun, Jan 28, 2018 at 3:20 PM, Akhil Lawrence 
wrote:

> I doubt whether you are reading my response properly. Let me reiterate my
> response for you.
>
>
> *There are two ways to do this. *
>
> *1. You can set the owner as the logged in user by default*
> *2. You can provide all possible owners as options and the user can select
> the owner from a dropdown.*
>
> *For case 1, you may not want to display the owner field in frontend. Here
> you can override form_valid and set the owner as logged in user.*
>
> *class CreateDog(CreateView):*
> *...*
> *def form_valid(self, form):*
> *form.instance.owner = self.request.user*
> *return super(CreateDog, self).form_valid(form)*
>
> *For more details:*
>
> *https://docs.djangoproject.com/en/2.0/topics/class-based-views/generic-editing/#models-and-request-user
> *
>
> *http://ccbv.co.uk/projects/Django/1.11/django.views.generic.edit/CreateView/#form_valid
> *
>
>
> *For case 2, you need to populate the list of owners by overriding the
> get_initial method.*
>
> *class CreateDog(CreateView):*
> *...*
> *def get_initial(self):*
> *initial_data = super(CreateDog, self).get_initial()*
> *initial_data["owner"] = [(x.id , x.name
> ) for x in Owner.objects.all()]*
> *return initial_data*
>
> *For more details:*
>
> *https://docs.djangoproject.com/en/2.0/ref/class-based-views/mixins-editing/#django.views.generic.edit.FormMixin.initial
> *
>
> *http://ccbv.co.uk/projects/Django/1.11/django.views.generic.edit/CreateView/#get_initial*
> 
>
>
> if you don't want to show the owner and want to associate the pet with
> owner via backend go for option1 (also note that you may need to remove the
> owner from fields of your createview)
> if you want to show a dropdown of possible owners go for option 2.
>
> If you need further assistance, please share your screen via chrome remote
> desktop or something and lets solve it
>
> Thanks.
>
>
> On Sunday, 28 January 2018 12:29:58 UTC+5:30, tangoward15 wrote:
>>
>> Sorry for being a drag, I tried this code:
>>
>> class CreateDog(CreateView):
>> template_name = 'dogs_cats/create_dog.html'
>> model = Dog
>> fields = ('name', 'bday', 'owner')
>>
>> def get_initial(self):
>> initial_data = super(CreateDog, self).get_initial()
>> initial_data["owner"] = [(self.request.user.id,
>> self.request.user.username)]
>> return initial_data
>>
>>
>> still I am getting the Admin user in the drop down list for owner.
>>
>> On Sun, Jan 28, 2018 at 2:31 PM, Akhil Lawrence 
>> wrote:
>>
>>>
>>> override get_initial and set only the logged in user
>>>
>>> class CreateDog(CreateView):
>>> ...
>>> def get_initial(self):
>>> initial_data = super(CreateDog, self).get_initial()
>>> initial_data["owner"] = [(self.request.user.id,
>>> self.request.user.username)]
>>> return initial_data
>>>
>>>
>>>
>>>
>>> On Sunday, 28 January 2018 11:52:31 UTC+5:30, tangoward15 wrote:

 I updated my models. py

 from django.db import models
 from django.contrib.auth import get_user_model
 from django.contrib.auth.models import User, PermissionsMixin

 # Create your models here.


 Pet_Owner = get_user_model()


 class RegisteredUser(User, PermissionsMixin):

 def __str__(self):
 return self.username


 class Dog(models.Model):
 name = models.CharField(max_length=40)
 bday = models.DateField()
 owner = models.ForeignKey(Pet_Owner, related_name='dogs',
 on_delete=models.CASCADE)

 def __str__(self):
 return self.name + ' - ' + str(self.owner)


 class Cat(models.Model):
 name = models.CharField(max_length=40)
 bday = models.DateField()
 owner = models.ForeignKey(Pet_Owner, related_name='cats',
 on_delete=models.CASCADE)

 def __str__(self):
 return self.name + ' - ' + str(self.owner)


 I can see all users as drop down list for owner field using Pet_Owner =
 get_user_model() .Problem is, it shows all the Users in the project not the
 only one who is currently logged in.

 On Sun, Jan 28, 2018 at 2:06 PM, Akhil Lawrence 
 wrote:

> Its the reverse. If the owner is deleted, all the cats and dogs
> associated with the owner will be deleted.
>

Re: CRUD code feedback

2018-01-27 Thread tango ward
Sorry for being a drag, I tried this code:

class CreateDog(CreateView):
template_name = 'dogs_cats/create_dog.html'
model = Dog
fields = ('name', 'bday', 'owner')

def get_initial(self):
initial_data = super(CreateDog, self).get_initial()
initial_data["owner"] = [(self.request.user.id,
self.request.user.username)]
return initial_data


still I am getting the Admin user in the drop down list for owner.

On Sun, Jan 28, 2018 at 2:31 PM, Akhil Lawrence 
wrote:

>
> override get_initial and set only the logged in user
>
> class CreateDog(CreateView):
> ...
> def get_initial(self):
> initial_data = super(CreateDog, self).get_initial()
> initial_data["owner"] = [(self.request.user.id,
> self.request.user.username)]
> return initial_data
>
>
>
>
> On Sunday, 28 January 2018 11:52:31 UTC+5:30, tangoward15 wrote:
>>
>> I updated my models. py
>>
>> from django.db import models
>> from django.contrib.auth import get_user_model
>> from django.contrib.auth.models import User, PermissionsMixin
>>
>> # Create your models here.
>>
>>
>> Pet_Owner = get_user_model()
>>
>>
>> class RegisteredUser(User, PermissionsMixin):
>>
>> def __str__(self):
>> return self.username
>>
>>
>> class Dog(models.Model):
>> name = models.CharField(max_length=40)
>> bday = models.DateField()
>> owner = models.ForeignKey(Pet_Owner, related_name='dogs',
>> on_delete=models.CASCADE)
>>
>> def __str__(self):
>> return self.name + ' - ' + str(self.owner)
>>
>>
>> class Cat(models.Model):
>> name = models.CharField(max_length=40)
>> bday = models.DateField()
>> owner = models.ForeignKey(Pet_Owner, related_name='cats',
>> on_delete=models.CASCADE)
>>
>> def __str__(self):
>> return self.name + ' - ' + str(self.owner)
>>
>>
>> I can see all users as drop down list for owner field using Pet_Owner =
>> get_user_model() .Problem is, it shows all the Users in the project not the
>> only one who is currently logged in.
>>
>> On Sun, Jan 28, 2018 at 2:06 PM, Akhil Lawrence 
>> wrote:
>>
>>> Its the reverse. If the owner is deleted, all the cats and dogs
>>> associated with the owner will be deleted.
>>>
>>> On Sunday, 28 January 2018 10:43:54 UTC+5:30, tangoward15 wrote:

 Will try it now.

 Quesion about the on_delete=models.CASCADE, does this mean that if I
 delete the pet (dog or cat) it will delete the owner who owns them?

 On Sun, Jan 28, 2018 at 1:11 PM, Akhil Lawrence 
 wrote:

> Your create view do not accept owner as a input and according to your
> models, owner can be null. That's the problem. Include owner to your 
> create
> view fields as shown below. Also you may consider making owner mandatory 
> as
> mentioned in my previous response.
>
>
> class CreateDog(CreateView):
> model = Dog
> fields = ('name', 'bday', 'owner')
> template_name = 'animals/dog_create.html'
>
>
> class CreateCat(CreateView):
> model = Cat
> fields = ('name', 'bday', 'owner')
> template_name = 'animals/cat_create.html'
>
> Thanks
>
> --
> 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 django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/340fa5fd-1475
> -4355-821c-82404b71b6bb%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

 --
>>> 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 django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/django-users/09d7c9ca-7dab-4787-94d9-09b3a1bc682a%40googlegroups.com
>>> 
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
> 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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at 

Re: CRUD code feedback

2018-01-27 Thread tango ward
I updated my models. py

from django.db import models
from django.contrib.auth import get_user_model
from django.contrib.auth.models import User, PermissionsMixin

# Create your models here.


Pet_Owner = get_user_model()


class RegisteredUser(User, PermissionsMixin):

def __str__(self):
return self.username


class Dog(models.Model):
name = models.CharField(max_length=40)
bday = models.DateField()
owner = models.ForeignKey(Pet_Owner, related_name='dogs',
on_delete=models.CASCADE)

def __str__(self):
return self.name + ' - ' + str(self.owner)


class Cat(models.Model):
name = models.CharField(max_length=40)
bday = models.DateField()
owner = models.ForeignKey(Pet_Owner, related_name='cats',
on_delete=models.CASCADE)

def __str__(self):
return self.name + ' - ' + str(self.owner)


I can see all users as drop down list for owner field using Pet_Owner =
get_user_model() .Problem is, it shows all the Users in the project not the
only one who is currently logged in.

On Sun, Jan 28, 2018 at 2:06 PM, Akhil Lawrence 
wrote:

> Its the reverse. If the owner is deleted, all the cats and dogs associated
> with the owner will be deleted.
>
> On Sunday, 28 January 2018 10:43:54 UTC+5:30, tangoward15 wrote:
>>
>> Will try it now.
>>
>> Quesion about the on_delete=models.CASCADE, does this mean that if I
>> delete the pet (dog or cat) it will delete the owner who owns them?
>>
>> On Sun, Jan 28, 2018 at 1:11 PM, Akhil Lawrence 
>> wrote:
>>
>>> Your create view do not accept owner as a input and according to your
>>> models, owner can be null. That's the problem. Include owner to your create
>>> view fields as shown below. Also you may consider making owner mandatory as
>>> mentioned in my previous response.
>>>
>>>
>>> class CreateDog(CreateView):
>>> model = Dog
>>> fields = ('name', 'bday', 'owner')
>>> template_name = 'animals/dog_create.html'
>>>
>>>
>>> class CreateCat(CreateView):
>>> model = Cat
>>> fields = ('name', 'bday', 'owner')
>>> template_name = 'animals/cat_create.html'
>>>
>>> Thanks
>>>
>>> --
>>> 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 django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/django-users/340fa5fd-1475-4355-821c-82404b71b6bb%40googlegroups.com
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
> 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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/09d7c9ca-7dab-4787-94d9-09b3a1bc682a%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLJHAucw119D%2BfjO_Y4ADANe82PSjFk4vxVJdNU_ESurWw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: CRUD code feedback

2018-01-27 Thread tango ward
When I added the owner field, it doesn't have any value though the user is
already registered.

how do i make it mandatory in createview?


owner = Owner.objects.create_user(username="blah", password="blah", email="
b...@blah.com")
dog = Dog(name="mydog", bday=datetime.today(), owner=owner).save()


On Sun, Jan 28, 2018 at 1:13 PM, tango ward <tangowar...@gmail.com> wrote:

> Will try it now.
>
> Quesion about the on_delete=models.CASCADE, does this mean that if I
> delete the pet (dog or cat) it will delete the owner who owns them?
>
> On Sun, Jan 28, 2018 at 1:11 PM, Akhil Lawrence <akhilputh...@gmail.com>
> wrote:
>
>> Your create view do not accept owner as a input and according to your
>> models, owner can be null. That's the problem. Include owner to your create
>> view fields as shown below. Also you may consider making owner mandatory as
>> mentioned in my previous response.
>>
>>
>> class CreateDog(CreateView):
>> model = Dog
>> fields = ('name', 'bday', 'owner')
>> template_name = 'animals/dog_create.html'
>>
>>
>> class CreateCat(CreateView):
>> model = Cat
>> fields = ('name', 'bday', 'owner')
>> template_name = 'animals/cat_create.html'
>>
>> Thanks
>>
>> --
>> 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 django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/340fa5fd-1475-4355-821c-82404b71b6bb%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLLNJE0vO%3DGbMEy00C9RO-J3dnT-hBOxAPcVYc-Y1t6_fA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: CRUD code feedback

2018-01-27 Thread tango ward
Will try it now.

Quesion about the on_delete=models.CASCADE, does this mean that if I delete
the pet (dog or cat) it will delete the owner who owns them?

On Sun, Jan 28, 2018 at 1:11 PM, Akhil Lawrence 
wrote:

> Your create view do not accept owner as a input and according to your
> models, owner can be null. That's the problem. Include owner to your create
> view fields as shown below. Also you may consider making owner mandatory as
> mentioned in my previous response.
>
>
> class CreateDog(CreateView):
> model = Dog
> fields = ('name', 'bday', 'owner')
> template_name = 'animals/dog_create.html'
>
>
> class CreateCat(CreateView):
> model = Cat
> fields = ('name', 'bday', 'owner')
> template_name = 'animals/cat_create.html'
>
> Thanks
>
> --
> 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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/340fa5fd-1475-4355-821c-82404b71b6bb%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLKoJ9TkUo-CvhxVFKVkyeHfVS-%2Bk4HRQNPk_1OW5%2B_Oqw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: CRUD code feedback

2018-01-27 Thread tango ward
Hi,

Thanks for the response Akhil,

I am using the CreateView in my view.py to create ne pets


class CreateDog(CreateView):
model = Dog
fields = ('name', 'bday')
template_name = 'animals/dog_create.html'


class CreateCat(CreateView):
model = Cat
fields = ('name', 'bday')
template_name = 'animals/cat_create.html'



On Sun, Jan 28, 2018 at 11:49 AM, Akhil Lawrence 
wrote:

> Hi Jarvis,
>
> The code which you have posted only shows the model. Within your cat and
> dog models the owner can be null. Which explains why the owner is not
> associated with the pets. Can I see the code you tried to insert the
> records?
>
> ## changes needed in models
> models.ForeignKey(Owner, related_name='cats', on_delete=models.CASCADE)
> models.ForeignKey(Owner, related_name='dogs', on_delete=models.CASCADE)
>
> ## code for inserting records
> owner = Owner.objects.create_user(username="blah", password="blah",
> email="b...@blah.com")
> dog = Dog(name="mydog", bday=datetime.today(), owner=owner).save()
>
>
> Thanks.
>
>
> On Sunday, 28 January 2018 07:10:31 UTC+5:30, tangoward15 wrote:
>>
>>
>> Hi,
>>
>> I am playing around with CRUD. I want a user a create an account first
>> before he/she can add pets under his/her profile. I tried adding one pet
>> however it's seems that it is not associated to the Owner who added the pet.
>>
>> models.py
>>
>> from django.db import models
>> from django.contrib.auth.models import User, PermissionsMixin
>> from django.urls import reverse
>> # Create your models here.
>>
>>
>> class Owner(User, PermissionsMixin):
>>
>> def __str__(self):
>> return self.username
>>
>>
>> class Cat(models.Model):
>> name = models.CharField(max_length=40)
>> bday = models.DateField()
>> owner = models.ForeignKey(Owner, related_name='cats', null=True,
>> on_delete=models.SET_NULL)
>>
>> def get_absolute_url(self):
>> return reverse('test')
>>
>> def __str__(self):
>> return self.name
>>
>>
>> class Dog(models.Model):
>> name = models.CharField(max_length=40)
>> bday = models.DateField()
>> owner = models.ForeignKey(Owner, related_name='dogs', null=True,
>> on_delete=models.SET_NULL)
>>
>> def get_absolute_url(self):
>> return reverse('test')
>>
>> def __str__(self):
>> return self.name
>>
>>
>> Any suggestions will be highly appreciated.
>>
>>
>> Regards,
>> Jarvis
>>
> --
> 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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/8f31afb0-2a9d-49ef-94b4-213aef140cf2%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQL%2BxQMxL7QVhWs%2Bx_mYST%3D5GRStGgEtjhz6XHvu49AFuEw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


CRUD code feedback

2018-01-27 Thread tango ward
Hi,

I am playing around with CRUD. I want a user a create an account first
before he/she can add pets under his/her profile. I tried adding one pet
however it's seems that it is not associated to the Owner who added the pet.

models.py

from django.db import models
from django.contrib.auth.models import User, PermissionsMixin
from django.urls import reverse
# Create your models here.


class Owner(User, PermissionsMixin):

def __str__(self):
return self.username


class Cat(models.Model):
name = models.CharField(max_length=40)
bday = models.DateField()
owner = models.ForeignKey(Owner, related_name='cats', null=True,
on_delete=models.SET_NULL)

def get_absolute_url(self):
return reverse('test')

def __str__(self):
return self.name


class Dog(models.Model):
name = models.CharField(max_length=40)
bday = models.DateField()
owner = models.ForeignKey(Owner, related_name='dogs', null=True,
on_delete=models.SET_NULL)

def get_absolute_url(self):
return reverse('test')

def __str__(self):
return self.name


Any suggestions will be highly appreciated.


Regards,
Jarvis

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQL%2BphX%3Dy8RnuHzfG1u7Z68%3Difpy6-3HFgVrQGitSCqBniA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


wsgi error

2018-01-26 Thread tango ward
Hi Team,

Not sure if this issue covered here but I am getting an error uploading my
pet project in Heroku.

ModuleNotFoundError: No module named 'animals.wsgi'

2018-01-27T02:59:26.637953+00:00 app[web.1]: [2018-01-27 02:59:26
+] [8] [INFO] Worker exiting (pid: 8)

2018-01-27T02:59:26.669632+00:00 app[web.1]: [2018-01-27 02:59:26
+] [4] [INFO] Shutting down: Master

2018-01-27T02:59:26.669770+00:00 app[web.1]: [2018-01-27 02:59:26
+] [4] [INFO] Reason: Worker failed to boot.



my Procfile in my root folder contains this:

web: gunicorn animals.wsgi:application --log-file - --log-level debug

where animals is the name of my project, where my wsgi.py file is residing.

I tried searching this in StackOverflow but most of the answers are saying
that it must be "web: gunicorn PROJECT_NAME.wsgi:application --log-file -
--log-level debug" which I already did in my Procfile.


Any suggestions?



Regards,
Jarvis

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLKi4vjKpVByRykvkXoPkpPUBprVq2pvmn-OabzSkAFoyQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: PostrgreSQL Inside Virtualenv

2018-01-24 Thread tango ward
Noted. Thanks

On Wed, Jan 24, 2018 at 5:56 PM, Avraham Serour <tovm...@gmail.com> wrote:

> In any case you'll need to pip install the postgres drivers for python, I
> suggest doing that inside the env
>
>
> On Wed, Jan 24, 2018 at 11:32 AM, tango ward <tangowar...@gmail.com>
> wrote:
>
>> Got it. Thanks Anoosha
>>
>> On Wed, Jan 24, 2018 at 5:29 PM, 'Anoosha Masood Keen' via Django users <
>> django-users@googlegroups.com> wrote:
>>
>>> Install it on your computer.
>>>
>>> On Wednesday, January 24, 2018 at 8:49:17 AM UTC, tangoward15 wrote:
>>>
>>>>
>>>> Hi,
>>>>
>>>>
>>>> Newbie question, since I installed django and pillow inside virtualenv,
>>>> shall I also install PostgreSQL inside Virtualenv? At the moment I am still
>>>> using SQLite in my pet project.
>>>>
>>>>
>>>> Regards,
>>>> Jarvis
>>>>
>>>>
>>>> --
>>> 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 django-users+unsubscr...@googlegroups.com.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/django-users/962726a2-e3b3-4ee1-b81b-c1227656b7da%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/962726a2-e3b3-4ee1-b81b-c1227656b7da%40googlegroups.com?utm_medium=email_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
>> 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 django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/CAA6wQLKYD2z4dvuxESSp67CSiDDOttMJuGxizhFHyV
>> RhA%2BHq6w%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAA6wQLKYD2z4dvuxESSp67CSiDDOttMJuGxizhFHyVRhA%2BHq6w%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> 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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAFWa6tLjsVTidO1X4v8wB%2BBukYTjKMiif4_CLFjqsPW_
> 3WdbDA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAFWa6tLjsVTidO1X4v8wB%2BBukYTjKMiif4_CLFjqsPW_3WdbDA%40mail.gmail.com?utm_medium=email_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLJEfdRHPR1nqYp%2BuY6-dagjAPmaBYm0WD0Famg2i2j52g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: PostrgreSQL Inside Virtualenv

2018-01-24 Thread tango ward
Got it. Thanks Anoosha

On Wed, Jan 24, 2018 at 5:29 PM, 'Anoosha Masood Keen' via Django users <
django-users@googlegroups.com> wrote:

> Install it on your computer.
>
> On Wednesday, January 24, 2018 at 8:49:17 AM UTC, tangoward15 wrote:
>
>>
>> Hi,
>>
>>
>> Newbie question, since I installed django and pillow inside virtualenv,
>> shall I also install PostgreSQL inside Virtualenv? At the moment I am still
>> using SQLite in my pet project.
>>
>>
>> Regards,
>> Jarvis
>>
>>
>> --
> 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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/962726a2-e3b3-4ee1-b81b-c1227656b7da%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLKYD2z4dvuxESSp67CSiDDOttMJuGxizhFHyVRhA%2BHq6w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: PostrgreSQL Inside Virtualenv

2018-01-24 Thread tango ward
Got it. Thanks Andréas

On Wed, Jan 24, 2018 at 5:12 PM, Andréas Kühne <andreas.ku...@hypercode.se>
wrote:

> Hi,
>
> The virtualenv is only for python things (django, pillow, the postgres
> connector). Postgres itself is a database server and needs to be installed
> on the host that you want to communicate with. It cannot be installed
> "only" in the virtualenv.
>
> Regards,
>
> Andréas
>
> 2018-01-24 9:59 GMT+01:00 tango ward <tangowar...@gmail.com>:
>
>> Hi Anoosha,
>>
>>
>> Thanks for the response. I'm just curious if the installation of
>> PostgreSQL should be inside Virtualenv too or should it be installed
>> directly into the computer.
>>
>> On Wed, Jan 24, 2018 at 4:55 PM, 'Anoosha Masood Keen' via Django users <
>> django-users@googlegroups.com> wrote:
>>
>>>
>>> Hi tangoward15. No need to install PostgreSQl at this stage. Just
>>> continue with the tutorial. SQLite works fine.
>>>
>>> On Wednesday, January 24, 2018 at 8:49:17 AM UTC, tangoward15 wrote:
>>>>
>>>>
>>>> Hi,
>>>>
>>>>
>>>> Newbie question, since I installed django and pillow inside virtualenv,
>>>> shall I also install PostgreSQL inside Virtualenv? At the moment I am still
>>>> using SQLite in my pet project.
>>>>
>>>>
>>>> Regards,
>>>> Jarvis
>>>>
>>>>
>>>> --
>>> 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 django-users+unsubscr...@googlegroups.com.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/django-users/5a31147a-423c-4cd9-8caf-f443aa75f45f%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/5a31147a-423c-4cd9-8caf-f443aa75f45f%40googlegroups.com?utm_medium=email_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
>> 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 django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/CAA6wQLK94jS2V8KFprd5_mtUeYpfk3A8VpeWSUrMmN
>> Lk2AnRNQ%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAA6wQLK94jS2V8KFprd5_mtUeYpfk3A8VpeWSUrMmNLk2AnRNQ%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> 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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAK4qSCcDeVfk%2B_D%3DzLSkGvqW1GxY1qRmXV3Xgij%3D-
> 8DPjG%2BmAQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAK4qSCcDeVfk%2B_D%3DzLSkGvqW1GxY1qRmXV3Xgij%3D-8DPjG%2BmAQ%40mail.gmail.com?utm_medium=email_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLLAOLYRP03hvcKiCeG3V%2BopLgOdwmUwfMAKTBUQ0OgW8Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: PostrgreSQL Inside Virtualenv

2018-01-24 Thread tango ward
Hi Anoosha,


Thanks for the response. I'm just curious if the installation of PostgreSQL
should be inside Virtualenv too or should it be installed directly into the
computer.

On Wed, Jan 24, 2018 at 4:55 PM, 'Anoosha Masood Keen' via Django users <
django-users@googlegroups.com> wrote:

>
> Hi tangoward15. No need to install PostgreSQl at this stage. Just
> continue with the tutorial. SQLite works fine.
>
> On Wednesday, January 24, 2018 at 8:49:17 AM UTC, tangoward15 wrote:
>>
>>
>> Hi,
>>
>>
>> Newbie question, since I installed django and pillow inside virtualenv,
>> shall I also install PostgreSQL inside Virtualenv? At the moment I am still
>> using SQLite in my pet project.
>>
>>
>> Regards,
>> Jarvis
>>
>>
>> --
> 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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/5a31147a-423c-4cd9-8caf-f443aa75f45f%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLK94jS2V8KFprd5_mtUeYpfk3A8VpeWSUrMmNLk2AnRNQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


PostrgreSQL Inside Virtualenv

2018-01-24 Thread tango ward
Hi,


Newbie question, since I installed django and pillow inside virtualenv,
shall I also install PostgreSQL inside Virtualenv? At the moment I am still
using SQLite in my pet project.


Regards,
Jarvis

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQL%2Bupi%3Dt_EDS15JNg0AostVBuW3-4qmUB9EOXJmx7ii%2BwA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Filter Json boolean data

2018-01-19 Thread tango ward
That works. Silly me.

Thank you Florian.

On Fri, Jan 19, 2018 at 7:32 PM, Florian Schweikert <kel...@ist-total.org>
wrote:

> Hi,
>
> On 19/01/18 11:50, tango ward wrote:
> > # Check who the winner of the match
> > if data['radiant_win'] == 'False':
>
> You are comparing a boolean with the *string* 'False', remove the ' and
> try again.
>
> > j_data['Winner'] = data['dire_name']
> > else:
> > j_data['Winner'] = data['radiant_name']
> >
> > # Put the data in our game_data list
> > game_data.append(j_data)
>
> --
> 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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/28f8e57a-2857-b5dc-c987-d4f378bb3247%40ist-total.org.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQL%2BqyJ6CtHDOqcHn7N%2B7F0w1auFEEDwoXnTBJKcNHwNPMg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Filter Json boolean data

2018-01-19 Thread tango ward
Hi guys,


I want to get the correct data if if key == false from a json data. My if
else condition seems to be working however the data is inconsistent. Here's
my code:


class DotaMatches(TemplateView):
template_name = 'matches/dota_matches.html'

def get(self, request, *args, **kwargs):
# Get the URL of the API using requests module
url = requests.get('https://api.opendota.com/api/proMatches')
# Decode the data
json_data = url.json()

# List that will contain dictionaries
game_data = []

for data in json_data:
# Will contain the values from the dictionary data of json_data
j_data = {}
j_data['League'] = data['league_name']
j_data['Radiant'] = data['radiant_name']
j_data['Dire'] = data['dire_name']
j_data['Duration'] = str(timedelta(seconds=data['duration']))
j_data['Finished'] = timeago.format(datetime.now() -
datetime.fromtimestamp(data['start_time']))

# Check who the winner of the match
if data['radiant_win'] == 'False':
j_data['Winner'] = data['dire_name']
else:
j_data['Winner'] = data['radiant_name']

# Put the data in our game_data list
game_data.append(j_data)

return render(request, self.template_name, {'game_data': game_data})


Not sure if there's something that I need to do first before running the if
- else condition.



Regards,
Jarvis

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLLfU_EsWf4AmNMHcraBkdqQgKSmPsBoMzfFfjfxu%2BYZZw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to parse json and display it in CBV.

2017-12-28 Thread tango ward
Thanks James.


I heard of serialization in REST but I haven't played around with it.
That's why I didn't know the exact terms of what I am doing.

On Thu, Dec 28, 2017 at 5:44 AM, James Schneider <jrschneide...@gmail.com>
wrote:

>
>
> On Dec 27, 2017 1:02 PM, "tango ward" <tangowar...@gmail.com> wrote:
>
> Follow up question. Apologies for the continuation.
>
> I tried integrating the API from OpenDOTA https://api.opendota.com/api/h
> eroes.
>
> my code:
>
> import requests
> import json
>
> url = requests.get('https://api.opendota.com/api/heroes')
> res = url.json()
>
> when I typed in 'res' in my terminal, it returns a List of dictionaries.
> Now, is it possible to turn this list to a dictionary? Apologies for the
> confusion, I am confuse as well.
>
>
> The terms you are looking for are serialization (converting Python objects
> to JSON) and deserialization (converting JSON to Python objects).
>
> If you're using requests, and you can successfully run the .json() method,
> then you successfully converted the JSON to a native Python structure.
>
> In this case, you are requesting a list of heroes, so you received a list
> back. You'll need to find the hero you want in the list using the standard
> methods of working with Python lists, access that element, and then you'll
> have access to the dict for that hero.
>
> There is probably a way to get a single dict for a specific hero from the
> API, but I'm not familiar with their API structure. You'll need to revert
> to their API documentation to determine the correct URL structure.
>
> -James
>
> --
> 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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CA%2Be%2BciUVLzj8%2BeZvwJo_tPGLy7-
> f33Nqwv4yf8v8GA3HdwBNEA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CA%2Be%2BciUVLzj8%2BeZvwJo_tPGLy7-f33Nqwv4yf8v8GA3HdwBNEA%40mail.gmail.com?utm_medium=email_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLLsH%3D9Vs4ph%3Dh_2Lg1nW3eppgqEn29haJXOLo0YSPPEdQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to parse json and display it in CBV.

2017-12-27 Thread tango ward
Follow up question. Apologies for the continuation.

I tried integrating the API from OpenDOTA
https://api.opendota.com/api/heroes.

my code:

import requests
import json

url = requests.get('https://api.opendota.com/api/heroes')
res = url.json()

when I typed in 'res' in my terminal, it returns a List of dictionaries.
Now, is it possible to turn this list to a dictionary? Apologies for the
confusion, I am confuse as well.


Regards,
Jarvis




On Wed, Dec 27, 2017 at 2:41 AM, tango ward <tangowar...@gmail.com> wrote:

> Thanks for the idea Andréas. You're always helping me.
>
> On Wed, Dec 27, 2017 at 2:29 AM, Andréas Kühne <andreas.ku...@hypercode.se
> > wrote:
>
>> All you need is to send the image (the url to the image) that should be
>> shown to the template, and then display it on the template. It shouldn't be
>> too hard as long as you understand how to send context data to the template.
>>
>> See here :
>> https://docs.djangoproject.com/en/2.0/topics/class-based-vie
>> ws/generic-display/#adding-extra-context
>>
>> Regards,
>>
>> Andréas
>>
>> 2017-12-26 19:07 GMT+01:00 tango ward <tangowar...@gmail.com>:
>>
>>> Hi Andréas,
>>>
>>> Thanks for the help.
>>>
>>> Also, I am not sure if the correct term is parse but I also want to
>>> display the images of heroes of DOTA 2 from OpenDOTA API. I saw a video on
>>> youtube on how to do it however its in Swift. Not sure if I can do it using
>>> CBV in django.
>>>
>>> On Wed, Dec 27, 2017 at 1:56 AM, Andréas Kühne <
>>> andreas.ku...@hypercode.se> wrote:
>>>
>>>> Hi,
>>>>
>>>> If you want to parse json in django - or in python for that matter -
>>>> all you have to do is to use the json module.
>>>>
>>>> import json
>>>>
>>>> object = json.loads(insert_string_here)
>>>>
>>>> insert_string_here is the string that you want to parse - and object is
>>>> the parsed json.
>>>>
>>>> Look here for more information: http://docs.pytho
>>>> n-guide.org/en/latest/scenarios/json/
>>>>
>>>> Regards,
>>>>
>>>> Andréas
>>>>
>>>> 2017-12-26 18:29 GMT+01:00 tango ward <tangowar...@gmail.com>:
>>>>
>>>>>
>>>>> Hi,
>>>>>
>>>>> I need suggestions on this.
>>>>>
>>>>> I want to use the OpenDOTA API for my pet project. As a beginner, I
>>>>> don't know where to start working on this. I have found the OpenDOTA API
>>>>> https://api.opendota.com/api/heroes which I am planning to use but I
>>>>> am confuse as to how to parse the json into my CBVs. I read this article
>>>>> https://godjango.com/blog/working-with-json-and-django/ but it
>>>>> doesn't show how to work with json in CBV.
>>>>>
>>>>> What I would like to achieve is to display all heroes from the
>>>>> OpenDOTA api link into my template.
>>>>>
>>>>> Can anyone shed some light on where should I start?
>>>>>
>>>>>
>>>>> Regards,
>>>>> Jarvis
>>>>>
>>>>> --
>>>>> 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 django-users+unsubscr...@googlegroups.com.
>>>>> To post to this group, send email to django-users@googlegroups.com.
>>>>> Visit this group at https://groups.google.com/group/django-users.
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/django-users/CAA6wQL%2BFW8
>>>>> ZGjgCxX2MKNr9e8mmR6xvsmZwSTufTeEFB54tjrA%40mail.gmail.com
>>>>> <https://groups.google.com/d/msgid/django-users/CAA6wQL%2BFW8ZGjgCxX2MKNr9e8mmR6xvsmZwSTufTeEFB54tjrA%40mail.gmail.com?utm_medium=email_source=footer>
>>>>> .
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>
>>>> --
>>>> 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 django-users+unsubscr...@googlegroups.com.
>>>> 

Re: How to parse json and display it in CBV.

2017-12-26 Thread tango ward
Thanks for the idea Andréas. You're always helping me.

On Wed, Dec 27, 2017 at 2:29 AM, Andréas Kühne <andreas.ku...@hypercode.se>
wrote:

> All you need is to send the image (the url to the image) that should be
> shown to the template, and then display it on the template. It shouldn't be
> too hard as long as you understand how to send context data to the template.
>
> See here :
> https://docs.djangoproject.com/en/2.0/topics/class-based-
> views/generic-display/#adding-extra-context
>
> Regards,
>
> Andréas
>
> 2017-12-26 19:07 GMT+01:00 tango ward <tangowar...@gmail.com>:
>
>> Hi Andréas,
>>
>> Thanks for the help.
>>
>> Also, I am not sure if the correct term is parse but I also want to
>> display the images of heroes of DOTA 2 from OpenDOTA API. I saw a video on
>> youtube on how to do it however its in Swift. Not sure if I can do it using
>> CBV in django.
>>
>> On Wed, Dec 27, 2017 at 1:56 AM, Andréas Kühne <
>> andreas.ku...@hypercode.se> wrote:
>>
>>> Hi,
>>>
>>> If you want to parse json in django - or in python for that matter - all
>>> you have to do is to use the json module.
>>>
>>> import json
>>>
>>> object = json.loads(insert_string_here)
>>>
>>> insert_string_here is the string that you want to parse - and object is
>>> the parsed json.
>>>
>>> Look here for more information: http://docs.pytho
>>> n-guide.org/en/latest/scenarios/json/
>>>
>>> Regards,
>>>
>>> Andréas
>>>
>>> 2017-12-26 18:29 GMT+01:00 tango ward <tangowar...@gmail.com>:
>>>
>>>>
>>>> Hi,
>>>>
>>>> I need suggestions on this.
>>>>
>>>> I want to use the OpenDOTA API for my pet project. As a beginner, I
>>>> don't know where to start working on this. I have found the OpenDOTA API
>>>> https://api.opendota.com/api/heroes which I am planning to use but I
>>>> am confuse as to how to parse the json into my CBVs. I read this article
>>>> https://godjango.com/blog/working-with-json-and-django/ but it doesn't
>>>> show how to work with json in CBV.
>>>>
>>>> What I would like to achieve is to display all heroes from the OpenDOTA
>>>> api link into my template.
>>>>
>>>> Can anyone shed some light on where should I start?
>>>>
>>>>
>>>> Regards,
>>>> Jarvis
>>>>
>>>> --
>>>> 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 django-users+unsubscr...@googlegroups.com.
>>>> To post to this group, send email to django-users@googlegroups.com.
>>>> Visit this group at https://groups.google.com/group/django-users.
>>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>>> gid/django-users/CAA6wQL%2BFW8ZGjgCxX2MKNr9e8mmR6xvsmZwSTufT
>>>> eEFB54tjrA%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/django-users/CAA6wQL%2BFW8ZGjgCxX2MKNr9e8mmR6xvsmZwSTufTeEFB54tjrA%40mail.gmail.com?utm_medium=email_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>> --
>>> 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 django-users+unsubscr...@googlegroups.com.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/django-users/CAK4qSCc%3DD43bpYNUXj3NmAqk2kR_fNnNBvTocVWT
>>> r44ioVT_mQ%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CAK4qSCc%3DD43bpYNUXj3NmAqk2kR_fNnNBvTocVWTr44ioVT_mQ%40mail.gmail.com?utm_medium=email_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
>> 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 django-users+unsubscr...@googlegroups.com.
>&

Re: How to parse json and display it in CBV.

2017-12-26 Thread tango ward
Hi Andréas,

Thanks for the help.

Also, I am not sure if the correct term is parse but I also want to display
the images of heroes of DOTA 2 from OpenDOTA API. I saw a video on youtube
on how to do it however its in Swift. Not sure if I can do it using CBV in
django.

On Wed, Dec 27, 2017 at 1:56 AM, Andréas Kühne <andreas.ku...@hypercode.se>
wrote:

> Hi,
>
> If you want to parse json in django - or in python for that matter - all
> you have to do is to use the json module.
>
> import json
>
> object = json.loads(insert_string_here)
>
> insert_string_here is the string that you want to parse - and object is
> the parsed json.
>
> Look here for more information: http://docs.python-guide.org/en/latest/
> scenarios/json/
>
> Regards,
>
> Andréas
>
> 2017-12-26 18:29 GMT+01:00 tango ward <tangowar...@gmail.com>:
>
>>
>> Hi,
>>
>> I need suggestions on this.
>>
>> I want to use the OpenDOTA API for my pet project. As a beginner, I don't
>> know where to start working on this. I have found the OpenDOTA API
>> https://api.opendota.com/api/heroes which I am planning to use but I am
>> confuse as to how to parse the json into my CBVs. I read this article
>> https://godjango.com/blog/working-with-json-and-django/ but it doesn't
>> show how to work with json in CBV.
>>
>> What I would like to achieve is to display all heroes from the OpenDOTA
>> api link into my template.
>>
>> Can anyone shed some light on where should I start?
>>
>>
>> Regards,
>> Jarvis
>>
>> --
>> 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 django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/CAA6wQL%2BFW8ZGjgCxX2MKNr9e8mmR6xvsmZwSTufT
>> eEFB54tjrA%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAA6wQL%2BFW8ZGjgCxX2MKNr9e8mmR6xvsmZwSTufTeEFB54tjrA%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> 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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAK4qSCc%3DD43bpYNUXj3NmAqk2kR_
> fNnNBvTocVWTr44ioVT_mQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAK4qSCc%3DD43bpYNUXj3NmAqk2kR_fNnNBvTocVWTr44ioVT_mQ%40mail.gmail.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLJPZmUcG28g%3Dxw%3DWODVHzT06ir1SfQRsnTWUGBV8uBgJQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


How to parse json and display it in CBV.

2017-12-26 Thread tango ward
Hi,

I need suggestions on this.

I want to use the OpenDOTA API for my pet project. As a beginner, I don't
know where to start working on this. I have found the OpenDOTA API
https://api.opendota.com/api/heroes which I am planning to use but I am
confuse as to how to parse the json into my CBVs. I read this article
https://godjango.com/blog/working-with-json-and-django/ but it doesn't show
how to work with json in CBV.

What I would like to achieve is to display all heroes from the OpenDOTA api
link into my template.

Can anyone shed some light on where should I start?


Regards,
Jarvis

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQL%2BFW8ZGjgCxX2MKNr9e8mmR6xvsmZwSTufTeEFB54tjrA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Filter data in related_name loop

2017-10-11 Thread tango ward
Hi guys, I've been scratching my head on this one. I want to know if it's
possible to filter the data of models class with related_name in a foor
loop? Basically, I want to show the members info associated to a Team.

models.py

class Team_Region(models.Model):
name = models.CharField(max_length=50)


# String representation
def __str__(self):
return self.name





class Team_Name(models.Model):
team_name = models.CharField(max_length=150)
logo = models.ImageField(upload_to='team_logos', blank=True)
region_member = models.ForeignKey(Team_Region,
related_name='region_mem')


def __str__(self):
return self.team_name + ' - ' + str(self.region_member)




class Team_Member(models.Model):
member_name = models.CharField(max_length=150)
position = models.CharField(max_length=50)
member_of_team = models.ForeignKey(Team_Name, related_name='team_mem')


def __str__(self):
return self.member_name + ' - ' + str(self.member_of_team)


views.py

# Listview of Regions
class TeamRegionListView(ListView):
context_object_name = 'region_name'
model = Team_Region
template_name = 'dota_teams/team_region_list.html'



# DetailView of Regions
class TeamRegionDetailView(DetailView):
context_object_name = 'team_names'
model = Team_Region
template_name = 'dota_teams/team_region_detail.html'



# DetailView of Teams. Will show team members
class TeamDetailView(DetailView):
context_object_name = 'team_members'
model = Team_Region
template_name = 'dota_teams/team_detail.html'

urls.py

url(r'^$', views.TeamRegionListView.as_view(), name='region_list'),
url(r'^(?P\d+)/$', views.TeamRegionDetailView.as_view(),
name='region_detail'),
url(r'^(?P\d+)/(\d+)/$', views.TeamDetailView.as_view(),
name='team_detail'),


Problem is, in my team_detail.html, for me to access the members' info, I
have these loops:


{% for team in team_members.region_mem.all %}
{% for member in team.team_mem.all %}


{{ member.member_name }}


{{ member.position }}



{% endfor %}
{% endfor %}


All members info will appear if i click a team which is not the way I want
it. I only want to show the members info associated to a team that I
clicked. This happens because I hae the team.team_mem.all in my loop which
basically shows all members data including those who are not part of the
team. Is there a way to filter this? My apologies for the long email.


TIA,
jarvis

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLKCC1duXTRdru67Ej0MyuvMKL17DM4QTh%2BBmxxsw%2BxeFQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Access data associated to a primary key

2017-10-03 Thread tango ward
thanks Gourav. I really appreciate your inputs.

On Tue, Oct 3, 2017 at 9:16 PM, Gourav Chawla <
gauravchawla.chawla...@gmail.com> wrote:

> Glad, you worked it out. You can use them whenever you want. Function
> based views require you to write more code but give you more clarity on
> what's happening. On the other hand CBV help you keep the codebase cleaner.
>
> At the end of the day, it's you who has to decide what to use.
>
> --
> 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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/efdec957-131b-4cfd-a0fc-0a37e52d3ea5%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQL%2BUGsZ9oQ9Zg7ZaVsNiB1MB2aq2PoYLEX8%2BHX0GpKQZPg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Access data associated to a primary key

2017-10-02 Thread tango ward
Holy .. it works!

I have to access the Team_Name class using the 'related_name=regions' and
from that, I was able to access the logo attributes of Team_Name.

Here's what I did.

{% block body_block %}


{% for region in regions_detail.regions.all %}





{% endfor %}


{% endblock %}


Thanks for your help Gourav. By the way, do you know when should I use CBV
and function view?

On Mon, Oct 2, 2017 at 9:31 PM, Gourav Chawla <
gauravchawla.chawla...@gmail.com> wrote:

> You can create another url, view, template to do that.
>
> Just create a url like : team/id
>
> For the above url create a view, say, teams_under_region which accepts the
> 'id'. Based on that id you can then query your database for teams where
> region_member=id. This is just the approach you would follow for functional
> view. But for CBV you have DetailView that takes care of this. Hope this
> helps.
>
>
> On Monday, October 2, 2017 at 2:53:04 PM UTC+5:30, tangoward15 wrote:
>>
>> Hi guys, I just want to know how to access and load the data associated
>> to a primary key in a template.
>>
>> models.py
>>
>> class Team_Region(models.Model):
>> name = models.CharField(max_length=50)
>>
>> # String representation
>> def __str__(self):
>> return self.name
>>
>>
>>
>> class Team_Name(models.Model):
>> t_name = models.CharField(max_length=100)
>> logo = models.ImageField(upload_to='team_logos', blank=True)
>> region_member = models.ForeignKey(Team_Region, related_name='regions')
>>
>>
>> def __str__(self):
>> return self.t_name + ' - ' + str(self.region_member)
>>
>>
>>
>>
>> views.py
>>
>> class TeamRegionListView(ListView):
>> context_object_name = 'regions_listview'
>> model = Team_Region
>> template_name = 'dota_teams/team_regions_list.html'
>>
>>
>> team_regions_list.html
>>
>> {% block body_block %}
>>
>> 
>> {% for region in regions_listview %}
>> 
>> {{
>> region.name }}
>> 
>> {% endfor %}
>> 
>>
>> {% endblock %}
>>
>>
>> What I want to achieve is to load the teams' logos and names when the
>> region name link is clicked in the team_regions.html. The teams that will
>> only be displayed in the template are the teams part of the specific ID
>> from Team_Region. Say, region is NA, I want all teams under NA to be
>> displayed in the template.
>>
>> Not sure how to do this using ListView.
>>
>> Any suggestions?
>>
>>
>> TIA
>>
> --
> 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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/1b7d75bb-e5ed-4cc5-8b30-7d6487dcb966%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLJGX5Ai_L6Cxv0c1BZWpdzwX8Z-pUuHu%3DdaVaxxuwVHyw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Access data associated to a primary key

2017-10-02 Thread tango ward
Hi Gourav, thanks for the input.

Just a question, Can I iterate through the Team_Region to get the teams
listed under the specific id? or shall I do it in Team_Member class? This
is for the DetailView.

On Mon, Oct 2, 2017 at 9:31 PM, Gourav Chawla <
gauravchawla.chawla...@gmail.com> wrote:

> You can create another url, view, template to do that.
>
> Just create a url like : team/id
>
> For the above url create a view, say, teams_under_region which accepts the
> 'id'. Based on that id you can then query your database for teams where
> region_member=id. This is just the approach you would follow for functional
> view. But for CBV you have DetailView that takes care of this. Hope this
> helps.
>
>
> On Monday, October 2, 2017 at 2:53:04 PM UTC+5:30, tangoward15 wrote:
>>
>> Hi guys, I just want to know how to access and load the data associated
>> to a primary key in a template.
>>
>> models.py
>>
>> class Team_Region(models.Model):
>> name = models.CharField(max_length=50)
>>
>> # String representation
>> def __str__(self):
>> return self.name
>>
>>
>>
>> class Team_Name(models.Model):
>> t_name = models.CharField(max_length=100)
>> logo = models.ImageField(upload_to='team_logos', blank=True)
>> region_member = models.ForeignKey(Team_Region, related_name='regions')
>>
>>
>> def __str__(self):
>> return self.t_name + ' - ' + str(self.region_member)
>>
>>
>>
>>
>> views.py
>>
>> class TeamRegionListView(ListView):
>> context_object_name = 'regions_listview'
>> model = Team_Region
>> template_name = 'dota_teams/team_regions_list.html'
>>
>>
>> team_regions_list.html
>>
>> {% block body_block %}
>>
>> 
>> {% for region in regions_listview %}
>> 
>> {{
>> region.name }}
>> 
>> {% endfor %}
>> 
>>
>> {% endblock %}
>>
>>
>> What I want to achieve is to load the teams' logos and names when the
>> region name link is clicked in the team_regions.html. The teams that will
>> only be displayed in the template are the teams part of the specific ID
>> from Team_Region. Say, region is NA, I want all teams under NA to be
>> displayed in the template.
>>
>> Not sure how to do this using ListView.
>>
>> Any suggestions?
>>
>>
>> TIA
>>
> --
> 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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/1b7d75bb-e5ed-4cc5-8b30-7d6487dcb966%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQL%2Bm%2BYCeFR8rur2NiStqFW_0NGVEH8S-G3KE7am8BSs1cA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Access data associated to a primary key

2017-10-02 Thread tango ward
Hi guys, I just want to know how to access and load the data associated to
a primary key in a template.

models.py

class Team_Region(models.Model):
name = models.CharField(max_length=50)

# String representation
def __str__(self):
return self.name



class Team_Name(models.Model):
t_name = models.CharField(max_length=100)
logo = models.ImageField(upload_to='team_logos', blank=True)
region_member = models.ForeignKey(Team_Region, related_name='regions')


def __str__(self):
return self.t_name + ' - ' + str(self.region_member)




views.py

class TeamRegionListView(ListView):
context_object_name = 'regions_listview'
model = Team_Region
template_name = 'dota_teams/team_regions_list.html'


team_regions_list.html

{% block body_block %}


{% for region in regions_listview %}

{{ region.name
}}

{% endfor %}


{% endblock %}


What I want to achieve is to load the teams' logos and names when the
region name link is clicked in the team_regions.html. The teams that will
only be displayed in the template are the teams part of the specific ID
from Team_Region. Say, region is NA, I want all teams under NA to be
displayed in the template.

Not sure how to do this using ListView.

Any suggestions?


TIA

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLLOPMnwZKpcXsx99GUsAr2f-mS8W6C_nQd1EA-OHBa_2A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: CharField vs ImageField for Logo

2017-09-26 Thread tango ward
Got it. Thanks a lot!!

On Tue, Sep 26, 2017 at 3:33 PM, Andréas Kühne <andreas.ku...@hypercode.se>
wrote:

> Hi,
>
> great that you are getting how the media settings work.
>
> If you look at this page : https://docs.djangoproject.
> com/en/1.11/howto/static-files/ it explains what static files are and how
> they work.  Basically, you use the static files template tags in your html
> templates and then you can use the same solution in development as in
> production. It's mainly good if you for example are serving your static
> files from your computer in development, but from a CDN i production (we do
> that on a project I wrote) and you then don't have to change anything but
> the settings file in production.
>
> The reason you need to add the configuration to your settings file is
> because the django runserver process doesn't know where to serve your files
> from otherwise. There are no "reasonable" defaults for those settings.
>
> Hope that helps!
>
> Andréas
>
> 2017-09-26 0:40 GMT+02:00 tango ward <tangowar...@gmail.com>:
>
>> Hi Andreas,
>>
>>
>> I was able to display the images but I dont know how they work. I checked
>> some online resources and found out that I need to add these in my urls.py
>>
>> from django.conf import settings
>> from django.conf.urls.static import static
>>
>> and at the bottom of it, I added
>>
>> if settings.DEBUG:
>> urlpatterns += static(settings.MEDIA_URL,
>> document_root=settings.MEDIA_ROOT)
>>
>>
>> I also saw a urlpattern for STATIC_URL and STATIC_ROOT.
>>
>> Would you have a minute or two to help me understand these codes?
>>
>> I would really appreciate it.
>>
>>
>> Thanks
>>
>> On Tue, Sep 26, 2017 at 5:23 AM, tango ward <tangowar...@gmail.com>
>> wrote:
>>
>>> Hi Andreas,
>>>
>>>
>>> Really appreciate your guidance on this.
>>>
>>> I am having trouble understanding this:
>>>
>>> 3: All that will be stored in your database is a path to the file
>>> (relative to MEDIA_ROOT
>>> <https://docs.djangoproject.com/en/1.11/ref/settings/#std:setting-MEDIA_ROOT>).
>>> You’ll most likely want to use the convenience url
>>> <https://docs.djangoproject.com/en/1.11/ref/models/fields/#django.db.models.fields.files.FieldFile.url>
>>> attribute provided by Django. For example, if your ImageField
>>> <https://docs.djangoproject.com/en/1.11/ref/models/fields/#django.db.models.ImageField>
>>> is called mug_shot, you can get the absolute path to your image in a
>>> template with {{ object.mug_shot.url }}.
>>>
>>>
>>> I tried applying the object.logo.url but the logo still doesn't display.
>>> Also where did the object and url came from?
>>>
>>> On Tue, Sep 26, 2017 at 3:39 AM, Andréas Kühne <
>>> andreas.ku...@hypercode.se> wrote:
>>>
>>>> Hi,
>>>>
>>>> I think you've made a lot of progress!
>>>>
>>>> The only thing I think you are missing now is that you should be using
>>>> the following in your template:
>>>> 
>>>>
>>>> See: https://docs.djangoproject.com/en/1.11/ref/models/field
>>>> s/#filefield and https://docs.djangoproject
>>>> .com/en/1.11/ref/models/fields/#django.db.models.fields.file
>>>> s.FieldFile.url
>>>>
>>>> Regards,
>>>>
>>>> Andréas
>>>>
>>>> 2017-09-25 20:38 GMT+02:00 tango ward <tangowar...@gmail.com>:
>>>>
>>>>> Hi Andréas,
>>>>>
>>>>>
>>>>> Thank you for the response.
>>>>>
>>>>> I added these lines in my settings.py
>>>>>
>>>>> MEDIA_DIR = os.path.join(BASE_DIR, 'media')
>>>>>
>>>>> # Media
>>>>>
>>>>> MEDIA_ROOT = MEDIA_DIR
>>>>> MEDIA_URL = '/media/
>>>>>
>>>>> Then I changed my logo to models.ImageField(upload_to='team_logo'). I
>>>>> also created a 'media' folder inside my project folder which team_logo is 
>>>>> a
>>>>> subfolder in it. Tried running the codes again but the logo still wont
>>>>> show.
>>>>>
>>>>>
>>>>> {% block body_block %}
>>>>>
>>>>> 
>>>>> 
>>>>> {% for team in teams %}
>>>>> 
>

Re: CharField vs ImageField for Logo

2017-09-25 Thread tango ward
Hi Andreas,


I was able to display the images but I dont know how they work. I checked
some online resources and found out that I need to add these in my urls.py

from django.conf import settings
from django.conf.urls.static import static

and at the bottom of it, I added

if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT)


I also saw a urlpattern for STATIC_URL and STATIC_ROOT.

Would you have a minute or two to help me understand these codes?

I would really appreciate it.


Thanks

On Tue, Sep 26, 2017 at 5:23 AM, tango ward <tangowar...@gmail.com> wrote:

> Hi Andreas,
>
>
> Really appreciate your guidance on this.
>
> I am having trouble understanding this:
>
> 3: All that will be stored in your database is a path to the file
> (relative to MEDIA_ROOT
> <https://docs.djangoproject.com/en/1.11/ref/settings/#std:setting-MEDIA_ROOT>).
> You’ll most likely want to use the convenience url
> <https://docs.djangoproject.com/en/1.11/ref/models/fields/#django.db.models.fields.files.FieldFile.url>
> attribute provided by Django. For example, if your ImageField
> <https://docs.djangoproject.com/en/1.11/ref/models/fields/#django.db.models.ImageField>
> is called mug_shot, you can get the absolute path to your image in a
> template with {{ object.mug_shot.url }}.
>
>
> I tried applying the object.logo.url but the logo still doesn't display.
> Also where did the object and url came from?
>
> On Tue, Sep 26, 2017 at 3:39 AM, Andréas Kühne <andreas.ku...@hypercode.se
> > wrote:
>
>> Hi,
>>
>> I think you've made a lot of progress!
>>
>> The only thing I think you are missing now is that you should be using
>> the following in your template:
>> 
>>
>> See: https://docs.djangoproject.com/en/1.11/ref/models/fields/#filefield
>> and https://docs.djangoproject.com/en/1.11/ref/models/
>> fields/#django.db.models.fields.files.FieldFile.url
>>
>> Regards,
>>
>> Andréas
>>
>> 2017-09-25 20:38 GMT+02:00 tango ward <tangowar...@gmail.com>:
>>
>>> Hi Andréas,
>>>
>>>
>>> Thank you for the response.
>>>
>>> I added these lines in my settings.py
>>>
>>> MEDIA_DIR = os.path.join(BASE_DIR, 'media')
>>>
>>> # Media
>>>
>>> MEDIA_ROOT = MEDIA_DIR
>>> MEDIA_URL = '/media/
>>>
>>> Then I changed my logo to models.ImageField(upload_to='team_logo'). I
>>> also created a 'media' folder inside my project folder which team_logo is a
>>> subfolder in it. Tried running the codes again but the logo still wont
>>> show.
>>>
>>>
>>> {% block body_block %}
>>>
>>> 
>>> 
>>> {% for team in teams %}
>>> 
>>>
>>> 
>>>  
>>>
>>> {{ team.name }}
>>> 
>>> {% endfor %}
>>> 
>>>
>>>
>>> {% endblock %}
>>>
>>>
>>> Is there any setting that I missed in media for media?
>>>
>>>
>>> Thanks,
>>> Jarvis
>>>
>>> On Mon, Sep 25, 2017 at 9:10 PM, Andréas Kühne <
>>> andreas.ku...@hypercode.se> wrote:
>>>
>>>> Hi,
>>>>
>>>> There are a couple of things to think about here.
>>>>
>>>> First of all - just because you put an item on your computer doesn't
>>>> mean that the icon can be served. For example, if you are running windows
>>>> and you enter 'C:\pictures\icon.jpg' as the source for the icon, your
>>>> server won't be able to find it, because the reference
>>>> 'C:\pictures\icon.jpg' doesn't mean anything for the web browser. The
>>>> reason the image links you are inputting work is because they probably
>>>> contain all information, ie http://www.example.com/pictures/icon.jpg.
>>>>
>>>> So you can get that sorted and everything should work. HOWEVER, I
>>>> really think you should use the media storage functionality of Django for
>>>> this. Checkout : https://docs.djangoproject.com/en/1.11/topics/files/.
>>>>
>>>> If you add the settings required (MEDIA_ROOT in the settings file) and
>>>> then change you logo from a CharField to an ImageField AND upload your file
>>>> via django admin, you should be able to show your file.
>>>>
>>>> Regards,
>>>>
>>>> Andréas
>>>>
>>>> 2017-09-25 1

Re: CharField vs ImageField for Logo

2017-09-25 Thread tango ward
Hi Andreas,


Really appreciate your guidance on this.

I am having trouble understanding this:

3: All that will be stored in your database is a path to the file (relative
to MEDIA_ROOT
<https://docs.djangoproject.com/en/1.11/ref/settings/#std:setting-MEDIA_ROOT>).
You’ll most likely want to use the convenience url
<https://docs.djangoproject.com/en/1.11/ref/models/fields/#django.db.models.fields.files.FieldFile.url>
attribute provided by Django. For example, if your ImageField
<https://docs.djangoproject.com/en/1.11/ref/models/fields/#django.db.models.ImageField>
is called mug_shot, you can get the absolute path to your image in a
template with {{ object.mug_shot.url }}.


I tried applying the object.logo.url but the logo still doesn't display.
Also where did the object and url came from?

On Tue, Sep 26, 2017 at 3:39 AM, Andréas Kühne <andreas.ku...@hypercode.se>
wrote:

> Hi,
>
> I think you've made a lot of progress!
>
> The only thing I think you are missing now is that you should be using the
> following in your template:
> 
>
> See: https://docs.djangoproject.com/en/1.11/ref/models/fields/#filefield
> and https://docs.djangoproject.com/en/1.11/ref/models/fields/#django.db.
> models.fields.files.FieldFile.url
>
> Regards,
>
> Andréas
>
> 2017-09-25 20:38 GMT+02:00 tango ward <tangowar...@gmail.com>:
>
>> Hi Andréas,
>>
>>
>> Thank you for the response.
>>
>> I added these lines in my settings.py
>>
>> MEDIA_DIR = os.path.join(BASE_DIR, 'media')
>>
>> # Media
>>
>> MEDIA_ROOT = MEDIA_DIR
>> MEDIA_URL = '/media/
>>
>> Then I changed my logo to models.ImageField(upload_to='team_logo'). I
>> also created a 'media' folder inside my project folder which team_logo is a
>> subfolder in it. Tried running the codes again but the logo still wont
>> show.
>>
>>
>> {% block body_block %}
>>
>> 
>> 
>> {% for team in teams %}
>> 
>>
>> 
>>  
>>
>> {{ team.name }}
>> 
>> {% endfor %}
>> 
>>
>>
>> {% endblock %}
>>
>>
>> Is there any setting that I missed in media for media?
>>
>>
>> Thanks,
>> Jarvis
>>
>> On Mon, Sep 25, 2017 at 9:10 PM, Andréas Kühne <
>> andreas.ku...@hypercode.se> wrote:
>>
>>> Hi,
>>>
>>> There are a couple of things to think about here.
>>>
>>> First of all - just because you put an item on your computer doesn't
>>> mean that the icon can be served. For example, if you are running windows
>>> and you enter 'C:\pictures\icon.jpg' as the source for the icon, your
>>> server won't be able to find it, because the reference
>>> 'C:\pictures\icon.jpg' doesn't mean anything for the web browser. The
>>> reason the image links you are inputting work is because they probably
>>> contain all information, ie http://www.example.com/pictures/icon.jpg.
>>>
>>> So you can get that sorted and everything should work. HOWEVER, I really
>>> think you should use the media storage functionality of Django for this.
>>> Checkout : https://docs.djangoproject.com/en/1.11/topics/files/.
>>>
>>> If you add the settings required (MEDIA_ROOT in the settings file) and
>>> then change you logo from a CharField to an ImageField AND upload your file
>>> via django admin, you should be able to show your file.
>>>
>>> Regards,
>>>
>>> Andréas
>>>
>>> 2017-09-25 14:38 GMT+02:00 tango ward <tangowar...@gmail.com>:
>>>
>>>>
>>>> Hi guys, I am new to django currently stuck in these two.
>>>>
>>>> I am writing my pet project which will display a Team name and their
>>>> logo. I used these lines for my Team class in mode.spy
>>>>
>>>>
>>>> class Team(models.Model):
>>>> name = models.CharField(max_length=150)
>>>> logo = models.CharField(null=True, max_length=1000)
>>>>
>>>>
>>>> def __str__(self):
>>>> return self.name
>>>>
>>>>
>>>> Problem is, I can't load the images to my html file My logo images are
>>>> currently stored in my computer. The images will load properly if I grab an
>>>> image link online and paste the image location to the Logo field in Admin
>>>> but if I used the absolute path of the images in my computer, the images
>>>> wont load. When I tried to in

Re: CharField vs ImageField for Logo

2017-09-25 Thread tango ward
Hi Andréas,


Thank you for the response.

I added these lines in my settings.py

MEDIA_DIR = os.path.join(BASE_DIR, 'media')

# Media

MEDIA_ROOT = MEDIA_DIR
MEDIA_URL = '/media/

Then I changed my logo to models.ImageField(upload_to='team_logo'). I also
created a 'media' folder inside my project folder which team_logo is a
subfolder in it. Tried running the codes again but the logo still wont
show.


{% block body_block %}



{% for team in teams %}



 

{{ team.name }}

{% endfor %}



{% endblock %}


Is there any setting that I missed in media for media?


Thanks,
Jarvis

On Mon, Sep 25, 2017 at 9:10 PM, Andréas Kühne <andreas.ku...@hypercode.se>
wrote:

> Hi,
>
> There are a couple of things to think about here.
>
> First of all - just because you put an item on your computer doesn't mean
> that the icon can be served. For example, if you are running windows and
> you enter 'C:\pictures\icon.jpg' as the source for the icon, your server
> won't be able to find it, because the reference 'C:\pictures\icon.jpg'
> doesn't mean anything for the web browser. The reason the image links you
> are inputting work is because they probably contain all information, ie
> http://www.example.com/pictures/icon.jpg.
>
> So you can get that sorted and everything should work. HOWEVER, I really
> think you should use the media storage functionality of Django for this.
> Checkout : https://docs.djangoproject.com/en/1.11/topics/files/.
>
> If you add the settings required (MEDIA_ROOT in the settings file) and
> then change you logo from a CharField to an ImageField AND upload your file
> via django admin, you should be able to show your file.
>
> Regards,
>
> Andréas
>
> 2017-09-25 14:38 GMT+02:00 tango ward <tangowar...@gmail.com>:
>
>>
>> Hi guys, I am new to django currently stuck in these two.
>>
>> I am writing my pet project which will display a Team name and their
>> logo. I used these lines for my Team class in mode.spy
>>
>>
>> class Team(models.Model):
>> name = models.CharField(max_length=150)
>> logo = models.CharField(null=True, max_length=1000)
>>
>>
>> def __str__(self):
>> return self.name
>>
>>
>> Problem is, I can't load the images to my html file My logo images are
>> currently stored in my computer. The images will load properly if I grab an
>> image link online and paste the image location to the Logo field in Admin
>> but if I used the absolute path of the images in my computer, the images
>> wont load. When I tried to inspect the page, I am getting "Image could not
>> load".
>>
>> Any tips please?
>>
>>
>> --
>> 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 django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/CAA6wQLJ6kjsd80%2BcmFOZhPB5C_1Ugnu%
>> 3Ds51aisfNgK%3DambvJUg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAA6wQLJ6kjsd80%2BcmFOZhPB5C_1Ugnu%3Ds51aisfNgK%3DambvJUg%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> 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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAK4qSCfrBi-0XwcHQLJHWRcfbZHDuXR-
> ciBx6xB1TR_AR82h%3Dg%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAK4qSCfrBi-0XwcHQLJHWRcfbZHDuXR-ciBx6xB1TR_AR82h%3Dg%40mail.gmail.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLLtaj5p1WPCZ3ozZFMFHyqjg%2B1AoDLzXq8qY79JNwg%3DwQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


CharField vs ImageField for Logo

2017-09-25 Thread tango ward
Hi guys, I am new to django currently stuck in these two.

I am writing my pet project which will display a Team name and their logo.
I used these lines for my Team class in mode.spy


class Team(models.Model):
name = models.CharField(max_length=150)
logo = models.CharField(null=True, max_length=1000)


def __str__(self):
return self.name


Problem is, I can't load the images to my html file My logo images are
currently stored in my computer. The images will load properly if I grab an
image link online and paste the image location to the Logo field in Admin
but if I used the absolute path of the images in my computer, the images
wont load. When I tried to inspect the page, I am getting "Image could not
load".

Any tips please?

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLJ6kjsd80%2BcmFOZhPB5C_1Ugnu%3Ds51aisfNgK%3DambvJUg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.