Re: How to make recursive ManyToMany relationships through an intermediate model symmetrical

2020-10-16 Thread coolguy

With your example, you can also find the records through>>> 
ted.person_set.all().

On Friday, October 16, 2020 at 7:05:51 PM UTC-4 David Nugent wrote:

> This is expected with your code.  You've created an asymmetric 
> relationship from bill to ted, but not the reverse. This would be 
> appropriate in a "follow" relationship. For symmetric relationships you 
> need to create records in both directions. There are a few ways to do this 
> but a helper function on the Person model is the most direct approach, 
> something along the lines:
>
> def add_friendship(self, person, symmetric=True):
> friendship = Friendship.objects.get_or_create(personA=self, 
> personB=person)
> if symmetric:
> # avoid recursion
> person.add_friendship(self, False)
> return friendship
>
>
> Regards, David
>
> On 17 Oct 2020, at 05:38, gjgilles via Django users <
> django...@googlegroups.com> wrote:
>
> There are no responses to the same question on stackoverflow, so hopefully 
> someone here can provide a solution. 
> 
>  
>
> I've read the docs. 
> 
>  I've read this question too, 
> 
>  but the following code is not working as the Django docs describe.
> If *bill* and *ted *are friends,* bill.friends.all() *should include 
> *ted,  *and *ted.friends.all() *should include *bill*. This is not what 
> Django does. *ted*'s query is empty, while *bill*'s query includes *ted*.
>
> # people.modelsfrom django.db import models
>
> class Person(models.Model):
> name = models.CharField(max_length=255)
> friends = models.ManyToManyField("self",
>  through='Friendship',
>  through_fields=('personA', 'personB'),
>  symmetrical=True,
>  )
>
> def __str__(self):
> return self.name
>
> class Friendship(models.Model):
> personA = models.ForeignKey(Person, on_delete=models.CASCADE, 
> related_name='personA')
> personB = models.ForeignKey(Person, on_delete=models.CASCADE, 
> related_name='personB')
> start = models.DateField(null=True, blank=True)
> end = models.DateField(null=True, blank=True)
>
> def __str__(self):
> return ' and '.join([str(self.personA), str(self.personB)])
>
>
>
>
> >>> import django
> >>> django.__version__
> '3.1.2'
> >>> from people.models import Person, Friendship>>> bill = 
> >>> Person(name='bill')>>> bill.save()>>> ted = Person(name='ted')>>> 
> >>> ted.save()>>> bill_and_ted = Friendship(personA=bill, personB=ted)>>> 
> >>> bill_and_ted.save()>>> bill.friends.all()
> ] ted.friends.all()
> >>> ted.refresh_from_db()>>> ted.friends.all()
> >>> ted = Person.objects.get(name='ted')>>> ted.friends.all()
> 
>
>
> Can someone please show me how to make this behave as expected.
>
>
> -- 
> 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/MJmh5Qw--3-2%40tutanota.com 
> 
> .
>
>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f1b39d06-6100-4b6c-94a5-1ec60fa45f80n%40googlegroups.com.


Re: could you help me to solve this problem? ☹☹

2020-09-29 Thread coolguy
Please share the project directories... Need to see if you opened the main 
project and application correctly.

On Tuesday, September 29, 2020 at 9:42:30 AM UTC-4 
farisch...@student.president.ac.id wrote:

> [image: Screenshot 2020-09-28 12.36.13.png]
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/40023cda-06ee-478a-a5cd-fdf26bfb123bn%40googlegroups.com.


Re: could you help me to solve this problem? ☹☹

2020-09-29 Thread coolguy
It seems you haven't changed your python interpreter...based on the screen 
shot the python is being executed from main python directory instead of 
virtual environment.

On Tuesday, September 29, 2020 at 9:42:30 AM UTC-4 
farisch...@student.president.ac.id wrote:

> [image: Screenshot 2020-09-28 12.36.13.png]
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/525ba3d8-5940-48c9-b656-c2be5b3fa559n%40googlegroups.com.


Re: Django admin page redirecting to some another page

2020-09-25 Thread coolguy
Please check if you have defined/changed LOGIN_URL settings in settings.py

On Friday, September 25, 2020 at 2:51:23 PM UTC-4 deepra...@gmail.com wrote:

> I go for super user login then it redirects to template which i made not 
> going to django admin login and django admin page,
>
> please suggest me any solution
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b568aa88-d340-44ac-a749-41c27af56e84n%40googlegroups.com.


Re: Django admin page redirecting to some another page

2020-09-25 Thread coolguy
Did you change LOGIN_REDIRECT_URL settings in settings.py?

On Friday, September 25, 2020 at 2:51:23 PM UTC-4 deepra...@gmail.com wrote:

> I go for super user login then it redirects to template which i made not 
> going to django admin login and django admin page,
>
> please suggest me any solution
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7bb1e7f7-be10-4ffa-b400-c1d1ad321fb9n%40googlegroups.com.


Re: Help me with the view please

2020-09-23 Thread coolguy
ohh i missed that...
in your urls.py

You may be using like this with 
path('student/fee//new/', views.AddFeeView.as_view(), name='add_fee'),

Since i have overridden PK configuration in view using 
pk_url_kwarg = 'student_id', I don't have to supply pk rather i have 
replaced it with student_id...
path('fee//new/', views.AddFeeView.as_view(), name='add_fee'),

On Wednesday, September 23, 2020 at 4:00:29 PM UTC-4 dex9...@gmail.com 
wrote:

> I cant seem to put together this template for adding fee, for roll#, 
> tuition fee and remaining fee, I have managed only to create the form, can 
> you help me with that
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Tuesday, September 22, 2020 6:10 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> how about following outputs... 
>
> On Tuesday, September 22, 2020 at 4:44:45 AM UTC-4 dex9...@gmail.com 
> wrote:
>
> Thanks for your previous tips, and I have already created the 
> get_absolute_url for my DetailView and It is working just fine
>
> *def* get_absolute_url(*self*):
>
> return reverse("student_detail", *kwargs*={"pk": self.pk})
>
> I think now I can learn from you how use views to generate my output
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Tuesday, September 22, 2020 4:32 AM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> I have made some changes to the model.py and now methods/functions are 
> properties(*@property*). It's of personal preference and you will find 
> programmers prefer properties and functions for their own understanding.
> google it you will see...
>
>  
>
> Since these functions are not doing big calculations with no 
> parameter/argument and are very basic so we can use property instead. 
>
>  
>
> What you need to do is.. wherever you called the method with () 
> brackets... remove them like example below...
>
>  
>
> fee = self.student.get_remaining_fee()
>
> to
>
> fee = self.student.get_remaining_fee
>
>  
>
> There is one get_absolute_url method that you can use to reverse to 
> student_detail view (if you have create one). We can later talk about how 
> you are using views to generate your output...
>
> On Monday, September 21, 2020 at 2:58:14 PM UTC-4 dex9...@gmail.com wrote:
>
> Hi @coolguy, thanks for your attachments,  have created all the views and 
> templates, and I have been working on them for my new web app, for this new 
> models will it be easy for more implement or auto check paid all checkbox 
> all payments have been completed, please, how?
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Thursday, September 17, 2020 6:26 AM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> If you are using sqllite3 then make a copy of it and delete the existing 
> sqllite3 file from your project. Keep the old file as you may need it.
>
>  
>
> Here are project files... i quickly make them but these are working..
>
>  
>
>  
>
>  
>
>  
>
> On Wednesday, September 16, 2020 at 3:57:22 PM UTC-4 dex9...@gmail.com 
> wrote:
>
> Since model design is where I very much struggle, and I think  my fee 
> management system models are not well design, so I need your help in 
> redesigning my models please
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Wednesday, September 16, 2020 5:31 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> There are a lot of courses but those are very basic and keep on talking 
> about same thing that you might have learned before... even after taking 
> courses you will have to think yourself how to structure your tables
>
>  
>
> I would suggest don't start any big project rather start with a simple 
> Student, Payment and Class models. Keep master information in your Student 
> and class models and all transaction in Payment model.
>
>  
>
> I can help you in designing the models.
>
>  
>
> Let me know...
>
>  
>
> On Wednesday, September 16, 2020 at 12:43:06 AM UTC-4 dex9...@gmail.com 
> wrote:
>
> Thanks for your valuable information, it seems my models are not well 
> constructed, I will first work on them.
>
> Don’t you have a YouTube chan

Re: Help me with the view please

2020-09-23 Thread coolguy
Now that you have structure ready... you can explore new options to pull 
the report with your requirement. I just created while watching NBA 
playoffs... so design may be silly...

Did you create view for adding fee?
Here is what i have done...

from django.views.generic.edit import CreateView
from . import forms

class AddFeeView(CreateView):
model = StudentFee
pk_url_kwarg = 'student_id'  # in createview pk would be parent table pk
template_name = 'students/fee_create_form.html'
form_class = forms.StudentFeeForm

def get_context_data(self, **kwargs):
student = Student.objects.get(id=self.kwargs['student_id'])

# adds the custom 'student' key to make it available to the
# class-based view template i.e. ('students/fee_create_form.html')
kwargs['student'] = student

# a call is made to the parent class’s get_context_data() method (i.e., 
CreateView)
# to run its context set up logic, which consists of setting up the 
form reference
# which is also used in the template. Finally, the context reference 
with all the
# template context values is returned by the get_context_data() method 
for use inside
# the template
context = super().get_context_data(**kwargs)

return context

def form_valid(self, form):
# form has only 
date, type and payment but student_id is empty at this time
obj = form.save(commit=False)
obj.student_id = self.kwargs.get('student_id')
obj.save()
# submit to super to save and redirect.
return super().form_valid(form)

Now you will have access to student and studentfee variables

you do can something like this on template

Roll# {{ student.id }} - {{ student.full_name }}
Tution fees: {{ student.tution_fee }}
Remaining Tution fees: {{ student.get_remaining_fee }}

On Wednesday, September 23, 2020 at 4:00:29 PM UTC-4 dex9...@gmail.com 
wrote:

> I cant seem to put together this template for adding fee, for roll#, 
> tuition fee and remaining fee, I have managed only to create the form, can 
> you help me with that
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Tuesday, September 22, 2020 6:10 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> how about following outputs... 
>
> On Tuesday, September 22, 2020 at 4:44:45 AM UTC-4 dex9...@gmail.com 
> wrote:
>
> Thanks for your previous tips, and I have already created the 
> get_absolute_url for my DetailView and It is working just fine
>
> *def* get_absolute_url(*self*):
>
> return reverse("student_detail", *kwargs*={"pk": self.pk})
>
> I think now I can learn from you how use views to generate my output
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Tuesday, September 22, 2020 4:32 AM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> I have made some changes to the model.py and now methods/functions are 
> properties(*@property*). It's of personal preference and you will find 
> programmers prefer properties and functions for their own understanding.
> google it you will see...
>
>  
>
> Since these functions are not doing big calculations with no 
> parameter/argument and are very basic so we can use property instead. 
>
>  
>
> What you need to do is.. wherever you called the method with () 
> brackets... remove them like example below...
>
>  
>
> fee = self.student.get_remaining_fee()
>
> to
>
> fee = self.student.get_remaining_fee
>
>  
>
> There is one get_absolute_url method that you can use to reverse to 
> student_detail view (if you have create one). We can later talk about how 
> you are using views to generate your output...
>
> On Monday, September 21, 2020 at 2:58:14 PM UTC-4 dex9...@gmail.com wrote:
>
> Hi @coolguy, thanks for your attachments,  have created all the views and 
> templates, and I have been working on them for my new web app, for this new 
> models will it be easy for more implement or auto check paid all checkbox 
> all payments have been completed, please, how?
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Thursday, September 17, 2020 6:26 AM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> If you are using sqllite3 then make a copy of it and delete the existing 
> sqllite3 file from your project. Keep the old file as you may need it.
>
>  
>
> Here are project files... i quickly ma

Re: Help me with the view please

2020-09-23 Thread coolguy
Now that you have structure ready... you can explore new options to pull 
the report with your requirement. I just created while watch NBA 
playoffs... so design may be silly...

Did you create view for adding fee?
Here is what i have done...

from django.views.generic.edit import CreateView
from . import forms

class AddFeeView(CreateView):
model = StudentFee
pk_url_kwarg = 'student_id'  # in createview pk would be parent table pk
template_name = 'students/fee_create_form.html'
form_class = forms.StudentFeeForm

def get_context_data(self, **kwargs):
student = Student.objects.get(id=self.kwargs['student_id'])

# adds the custom 'student' key to make it available to the
# class-based view template i.e. ('students/fee_create_form.html')
kwargs['student'] = student

# a call is made to the parent class’s get_context_data() method (i.e., 
CreateView)
# to run its context set up logic, which consists of setting up the 
form reference
# which is also used in the template. Finally, the context reference 
with all the
# template context values is returned by the get_context_data() method 
for use inside
# the template
context = super().get_context_data(**kwargs)

return context

def form_valid(self, form):
# form has only 
date, type and payment but student_id is empty at this time
obj = form.save(commit=False)
obj.student_id = self.kwargs.get('student_id')
obj.save()
# submit to super to save and redirect.
return super().form_valid(form)

Now you will have access to student and studentfee variables

you can something like this on template

Roll# {{ student.id }} - {{ student.full_name }}
Tution fees: {{ student.tution_fee }}
Remaining Tution fees: {{ student.get_remaining_fee }}

On Wednesday, September 23, 2020 at 4:00:29 PM UTC-4 dex9...@gmail.com 
wrote:

> I cant seem to put together this template for adding fee, for roll#, 
> tuition fee and remaining fee, I have managed only to create the form, can 
> you help me with that
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Tuesday, September 22, 2020 6:10 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> how about following outputs... 
>
> On Tuesday, September 22, 2020 at 4:44:45 AM UTC-4 dex9...@gmail.com 
> wrote:
>
> Thanks for your previous tips, and I have already created the 
> get_absolute_url for my DetailView and It is working just fine
>
> *def* get_absolute_url(*self*):
>
> return reverse("student_detail", *kwargs*={"pk": self.pk})
>
> I think now I can learn from you how use views to generate my output
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Tuesday, September 22, 2020 4:32 AM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> I have made some changes to the model.py and now methods/functions are 
> properties(*@property*). It's of personal preference and you will find 
> programmers prefer properties and functions for their own understanding.
> google it you will see...
>
>  
>
> Since these functions are not doing big calculations with no 
> parameter/argument and are very basic so we can use property instead. 
>
>  
>
> What you need to do is.. wherever you called the method with () 
> brackets... remove them like example below...
>
>  
>
> fee = self.student.get_remaining_fee()
>
> to
>
> fee = self.student.get_remaining_fee
>
>  
>
> There is one get_absolute_url method that you can use to reverse to 
> student_detail view (if you have create one). We can later talk about how 
> you are using views to generate your output...
>
> On Monday, September 21, 2020 at 2:58:14 PM UTC-4 dex9...@gmail.com wrote:
>
> Hi @coolguy, thanks for your attachments,  have created all the views and 
> templates, and I have been working on them for my new web app, for this new 
> models will it be easy for more implement or auto check paid all checkbox 
> all payments have been completed, please, how?
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Thursday, September 17, 2020 6:26 AM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> If you are using sqllite3 then make a copy of it and delete the existing 
> sqllite3 file from your project. Keep the old file as you may need it.
>
>  
>
> Here are project files... i quickly make th

Re: MultiValueDictKeyError at

2020-09-23 Thread coolguy
please share the views.py and template i.e. xxx.html.  i'ts not possible to 
tell what's wrong with the provided information

On Wednesday, September 23, 2020 at 11:43:36 AM UTC-4 luca72.b...@gmail.com 
wrote:

> Hello i have this problem :
> MultiValueDictKeyError at 
> The view is:
> matricola = request.POST['matricola']
>
> The form is:
>
> matricola = forms.CharField(label='Matricola',  required = False, 
> max_length=100, widget = forms.TextInput(attrs={'readonly':'readonly'}))
>
> the template is 
>
> {{ form }}
>
> Why i get this error? 
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9287bb2a-84a2-42ba-87a7-40344f75ecdcn%40googlegroups.com.


Re: ModelAdmin Not work

2020-09-23 Thread coolguy
either use admin.site.register
OR
*@*admin.register(User)

On Wednesday, September 23, 2020 at 11:01:43 AM UTC-4 kkwaq...@gmail.com 
wrote:

> *models.py*
>
> [image: 1.jpg]
>
> *admin.py*
>
> *[image: 2.jpg]*
>
> *errors*
>
>
> *[image: 3.jpg]*
>
> *Object is not callable*
>
> *Please any body solutions *
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/00354cdd-5478-4ee5-9e44-95098e393c83n%40googlegroups.com.


Re: How can I filter django many to many models?

2020-09-22 Thread coolguy
in your line below you are using field named '*vendor_details*' which 
should be in User model... but i don't see it there... can you please check 
again

seller_list = *User*.objects.select_related('*vendor_details*')  

On Tuesday, September 22, 2020 at 2:21:13 AM UTC-4 asadliv...@gmail.com 
wrote:

> class User(PermissionsMixin, AbstractBaseUser):
> name = models.CharField(max_length=511, null=True, blank=True)
> email = models.EmailField(unique=True)
> phone_number = PossiblePhoneNumberField(blank=True, null=True, default=
> None)
>
> addresses = models.ManyToManyField(Address, blank=True)
> is_staff = models.BooleanField(default=False)
> is_active = models.BooleanField(default=True)
> # is_featured = models.BooleanField(default=True)
> note = models.TextField(null=True, blank=True)
> date_joined = models.DateTimeField(default=timezone.now, editable=False)
> default_shipping_address = models.ForeignKey(
> Address, related_name='+', null=True, blank=True,
> on_delete=models.SET_NULL)
> default_billing_address = models.ForeignKey(
> Address, related_name='+', null=True, blank=True,
> on_delete=models.SET_NULL)
>
> class Order(models.Model):
> created = models.DateTimeField(
> default=now, editable=False)
> status = models.CharField(
> max_length=32, default=OrderStatus.UNFULFILLED,
> choices=OrderStatus.CHOICES)
> buyer_user = models.ForeignKey(
> settings.AUTH_USER_MODEL, blank=True, null=True, related_name=
> 'buyer_orders',
> on_delete=models.SET_NULL)
> vendor_users = models.ManyToManyField(
> settings.AUTH_USER_MODEL, blank=True, related_name='vendor_orders')
>
> order_updated_by = models.ForeignKey(settings.AUTH_USER_MODEL, 
> related_name='order_updated_user',
> on_delete=models.SET_NULL,
> blank=True, null=True)
>
> is_ready_for_aadibd = models.BooleanField(default=False)
> is_ready_for_shipment = models.BooleanField(default=False)
> is_delivered = models.BooleanField(default=False)
>
> seller_list = 
> User.objects.select_related('vendor_details').prefetch_related('vendor_orders').filter(
>  
> groups__name="vendor", vendor_details__isnull=False, 
> vendor_orders__is_delivered=True).order_by( 
> 'vendor_details__company_name').distinct()
> User.objects.select_related('vendor_details').prefetch_related('vendor_orders').filter(
>  
> groups__name="vendor", vendor_details__isnull=False, 
> vendor_orders__is_delivered=True).order_by( 
> 'vendor_details__company_name').distinct()
>
> *Date filter*
> seller_list = 
> seller_list.filter(vendor_orders__created__date__gte=default_last_month_start_days,
>  
> vendor_orders__created__date__lte=default_last_month_last_days)
>
>
>
> Also I'm using filter with exclude(is_delivered=False), but I didn't get 
> my results.
>
> I would like to filter (also using date, order id) my User who has 
> delivery status only is_delivered=True. I want only users for who all of 
> their deliveries are delivered. Like order id 2980 and It was associated 
> with three sellers. I got the three sellers when I filtered. How can I do 
> that?
>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/062705d5-695b-4e25-9b42-5c624286c5ffn%40googlegroups.com.


Re: How can I filter django many to many models?

2020-09-22 Thread coolguy
in your line below you are using field named 'vendor_details' which should 
be in User mode... but i don't see it there... can you please check again

seller_list = *User*.objects.select_related('*vendor_details*')  

On Tuesday, September 22, 2020 at 2:21:13 AM UTC-4 asadliv...@gmail.com 
wrote:

> class User(PermissionsMixin, AbstractBaseUser):
> name = models.CharField(max_length=511, null=True, blank=True)
> email = models.EmailField(unique=True)
> phone_number = PossiblePhoneNumberField(blank=True, null=True, default=
> None)
>
> addresses = models.ManyToManyField(Address, blank=True)
> is_staff = models.BooleanField(default=False)
> is_active = models.BooleanField(default=True)
> # is_featured = models.BooleanField(default=True)
> note = models.TextField(null=True, blank=True)
> date_joined = models.DateTimeField(default=timezone.now, editable=False)
> default_shipping_address = models.ForeignKey(
> Address, related_name='+', null=True, blank=True,
> on_delete=models.SET_NULL)
> default_billing_address = models.ForeignKey(
> Address, related_name='+', null=True, blank=True,
> on_delete=models.SET_NULL)
>
> class Order(models.Model):
> created = models.DateTimeField(
> default=now, editable=False)
> status = models.CharField(
> max_length=32, default=OrderStatus.UNFULFILLED,
> choices=OrderStatus.CHOICES)
> buyer_user = models.ForeignKey(
> settings.AUTH_USER_MODEL, blank=True, null=True, related_name=
> 'buyer_orders',
> on_delete=models.SET_NULL)
> vendor_users = models.ManyToManyField(
> settings.AUTH_USER_MODEL, blank=True, related_name='vendor_orders')
>
> order_updated_by = models.ForeignKey(settings.AUTH_USER_MODEL, 
> related_name='order_updated_user',
> on_delete=models.SET_NULL,
> blank=True, null=True)
>
> is_ready_for_aadibd = models.BooleanField(default=False)
> is_ready_for_shipment = models.BooleanField(default=False)
> is_delivered = models.BooleanField(default=False)
>
> seller_list = 
> User.objects.select_related('vendor_details').prefetch_related('vendor_orders').filter(
>  
> groups__name="vendor", vendor_details__isnull=False, 
> vendor_orders__is_delivered=True).order_by( 
> 'vendor_details__company_name').distinct()
> User.objects.select_related('vendor_details').prefetch_related('vendor_orders').filter(
>  
> groups__name="vendor", vendor_details__isnull=False, 
> vendor_orders__is_delivered=True).order_by( 
> 'vendor_details__company_name').distinct()
>
> *Date filter*
> seller_list = 
> seller_list.filter(vendor_orders__created__date__gte=default_last_month_start_days,
>  
> vendor_orders__created__date__lte=default_last_month_last_days)
>
>
>
> Also I'm using filter with exclude(is_delivered=False), but I didn't get 
> my results.
>
> I would like to filter (also using date, order id) my User who has 
> delivery status only is_delivered=True. I want only users for who all of 
> their deliveries are delivered. Like order id 2980 and It was associated 
> with three sellers. I got the three sellers when I filtered. How can I do 
> that?
>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c5e0505a-6e1f-47b9-bb73-36da5f90a246n%40googlegroups.com.


Re: Help me with the view please

2020-09-21 Thread coolguy
I have made some changes to the model.py and now methods/functions are 
properties(*@property*). It's of personal preference and you will find 
programmers prefer properties and functions for their own understanding.
google it you will see

Since these functions are not doing big calculations with no 
parameter/argument and are very basic so we can use property instead. 

What you need to do is... wherever you called the method with () 
brackets... remove them like example below...

fee = self.student.get_remaining_fee()
to
fee = self.student.get_remaining_fee

There is one get_absolute_url method that you can use to reverse to 
student_detail view (if you have create one). We can later talk about how 
you are using views to generate your output...
On Monday, September 21, 2020 at 2:58:14 PM UTC-4 dex9...@gmail.com wrote:

> Hi @coolguy, thanks for your attachments,  have created all the views and 
> templates, and I have been working on them for my new web app, for this new 
> models will it be easy for more implement or auto check paid all checkbox 
> all payments have been completed, please, how?
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Thursday, September 17, 2020 6:26 AM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> If you are using sqllite3 then make a copy of it and delete the existing 
> sqllite3 file from your project. Keep the old file as you may need it.
>
>  
>
> Here are project files... i quickly make them but these are working..
>
>  
>
>  
>
>  
>
>  
>
> On Wednesday, September 16, 2020 at 3:57:22 PM UTC-4 dex9...@gmail.com 
> wrote:
>
> Since model design is where I very much struggle, and I think  my fee 
> management system models are not well design, so I need your help in 
> redesigning my models please
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Wednesday, September 16, 2020 5:31 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> There are a lot of courses but those are very basic and keep on talking 
> about same thing that you might have learned before... even after taking 
> courses you will have to think yourself how to structure your tables
>
>  
>
> I would suggest don't start any big project rather start with a simple 
> Student, Payment and Class models. Keep master information in your Student 
> and class models and all transaction in Payment model.
>
>  
>
> I can help you in designing the models.
>
>  
>
> Let me know...
>
>  
>
> On Wednesday, September 16, 2020 at 12:43:06 AM UTC-4 dex9...@gmail.com 
> wrote:
>
> Thanks for your valuable information, it seems my models are not well 
> constructed, I will first work on them.
>
> Don’t you have a YouTube channel or website or paid course somewhere like 
> Udemy where I can learn more
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Tuesday, September 15, 2020 10:57 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> Isn't this 'paid_fee' used to record the quarterly/monthly payments from 
> students? and this field will have multiple records? 
>
>  
>
> It seems you are looking to save an accumulated paid_fee (total_paid_fees) 
> somewhere in table. 
>
> If i am corrected then... this type of structure is okay when you are 
> working on spreadsheet solution e.g. microsoft excel, and save/calculate 
> the result in a separate column for the user info but when we deal with the 
> database and UI solution we don't use this approach... rather we show such 
> calculation on template. We persist initial setup values like student name, 
> school_fees etc and the recurring transactions in database.
>
>  
>
> If you really want to save this type of information in your database you 
> get to change your database structure and create a parent and child 
> relationship between Fee (being parent) and Student_Payments (being child). 
> 'Fee' would have all setup information as well as calculated fields like 
> total_fees, total_paid_fees, remaining_fees etc. 'Student_payments' would 
> only carry number of payments over the periods. When you have this 
> structure ready then you can think of maintaining totals in parent table 
> per student.
>
>  
>
> anyways, to your question following line would not work in save() method
>
> >>> self.paid_fees = *student*.fee_set.aggregate(*total_paid

Re: Help me with the view please

2020-09-21 Thread coolguy
write me directly so i can respond fast... naseem.pyt...@gmail.com

On Monday, September 21, 2020 at 2:58:14 PM UTC-4 dex9...@gmail.com wrote:

> Hi @coolguy, thanks for your attachments,  have created all the views and 
> templates, and I have been working on them for my new web app, for this new 
> models will it be easy for more implement or auto check paid all checkbox 
> all payments have been completed, please, how?
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Thursday, September 17, 2020 6:26 AM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> If you are using sqllite3 then make a copy of it and delete the existing 
> sqllite3 file from your project. Keep the old file as you may need it.
>
>  
>
> Here are project files... i quickly make them but these are working..
>
>  
>
>  
>
>  
>
>  
>
> On Wednesday, September 16, 2020 at 3:57:22 PM UTC-4 dex9...@gmail.com 
> wrote:
>
> Since model design is where I very much struggle, and I think  my fee 
> management system models are not well design, so I need your help in 
> redesigning my models please
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Wednesday, September 16, 2020 5:31 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> There are a lot of courses but those are very basic and keep on talking 
> about same thing that you might have learned before... even after taking 
> courses you will have to think yourself how to structure your tables
>
>  
>
> I would suggest don't start any big project rather start with a simple 
> Student, Payment and Class models. Keep master information in your Student 
> and class models and all transaction in Payment model.
>
>  
>
> I can help you in designing the models.
>
>  
>
> Let me know...
>
>  
>
> On Wednesday, September 16, 2020 at 12:43:06 AM UTC-4 dex9...@gmail.com 
> wrote:
>
> Thanks for your valuable information, it seems my models are not well 
> constructed, I will first work on them.
>
> Don’t you have a YouTube channel or website or paid course somewhere like 
> Udemy where I can learn more
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Tuesday, September 15, 2020 10:57 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> Isn't this 'paid_fee' used to record the quarterly/monthly payments from 
> students? and this field will have multiple records? 
>
>  
>
> It seems you are looking to save an accumulated paid_fee (total_paid_fees) 
> somewhere in table. 
>
> If i am corrected then... this type of structure is okay when you are 
> working on spreadsheet solution e.g. microsoft excel, and save/calculate 
> the result in a separate column for the user info but when we deal with the 
> database and UI solution we don't use this approach... rather we show such 
> calculation on template. We persist initial setup values like student name, 
> school_fees etc and the recurring transactions in database.
>
>  
>
> If you really want to save this type of information in your database you 
> get to change your database structure and create a parent and child 
> relationship between Fee (being parent) and Student_Payments (being child). 
> 'Fee' would have all setup information as well as calculated fields like 
> total_fees, total_paid_fees, remaining_fees etc. 'Student_payments' would 
> only carry number of payments over the periods. When you have this 
> structure ready then you can think of maintaining totals in parent table 
> per student.
>
>  
>
> anyways, to your question following line would not work in save() method
>
> >>> self.paid_fees = *student*.fee_set.aggregate(*total_paid_fees*
> =sum('paid_fees'))  
>
>  
>
> since you don't have 
>
> >>> *student* = Student.objects.get(id=pk)
>
>  
>
> even if you want to save then which record in the table would you 
> update... so logically its wrong.
>
>  
>
> On Tuesday, September 15, 2020 at 2:04:57 AM UTC-4 dex9...@gmail.com 
> wrote:
>
> *def* save(*self*, **args*, ***kwargs*):
>
> self.paid_fees = student.fee_set.aggregate(*total_paid_fees*=sum(
> 'paid_fees'))
>
> self.school_fees = first_record.school_fees
>
> self.remaining_fees = self.school_fees - self.paid_fees
>
> if self.rema

Re: Help me with the view please

2020-09-21 Thread coolguy
checkout my work for you on https://github.com/naseemfico/students

On Monday, September 21, 2020 at 2:58:14 PM UTC-4 dex9...@gmail.com wrote:

> Hi @coolguy, thanks for your attachments,  have created all the views and 
> templates, and I have been working on them for my new web app, for this new 
> models will it be easy for more implement or auto check paid all checkbox 
> all payments have been completed, please, how?
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Thursday, September 17, 2020 6:26 AM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> If you are using sqllite3 then make a copy of it and delete the existing 
> sqllite3 file from your project. Keep the old file as you may need it.
>
>  
>
> Here are project files... i quickly make them but these are working..
>
>  
>
>  
>
>  
>
>  
>
> On Wednesday, September 16, 2020 at 3:57:22 PM UTC-4 dex9...@gmail.com 
> wrote:
>
> Since model design is where I very much struggle, and I think  my fee 
> management system models are not well design, so I need your help in 
> redesigning my models please
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Wednesday, September 16, 2020 5:31 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> There are a lot of courses but those are very basic and keep on talking 
> about same thing that you might have learned before... even after taking 
> courses you will have to think yourself how to structure your tables
>
>  
>
> I would suggest don't start any big project rather start with a simple 
> Student, Payment and Class models. Keep master information in your Student 
> and class models and all transaction in Payment model.
>
>  
>
> I can help you in designing the models.
>
>  
>
> Let me know...
>
>  
>
> On Wednesday, September 16, 2020 at 12:43:06 AM UTC-4 dex9...@gmail.com 
> wrote:
>
> Thanks for your valuable information, it seems my models are not well 
> constructed, I will first work on them.
>
> Don’t you have a YouTube channel or website or paid course somewhere like 
> Udemy where I can learn more
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Tuesday, September 15, 2020 10:57 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> Isn't this 'paid_fee' used to record the quarterly/monthly payments from 
> students? and this field will have multiple records? 
>
>  
>
> It seems you are looking to save an accumulated paid_fee (total_paid_fees) 
> somewhere in table. 
>
> If i am corrected then... this type of structure is okay when you are 
> working on spreadsheet solution e.g. microsoft excel, and save/calculate 
> the result in a separate column for the user info but when we deal with the 
> database and UI solution we don't use this approach... rather we show such 
> calculation on template. We persist initial setup values like student name, 
> school_fees etc and the recurring transactions in database.
>
>  
>
> If you really want to save this type of information in your database you 
> get to change your database structure and create a parent and child 
> relationship between Fee (being parent) and Student_Payments (being child). 
> 'Fee' would have all setup information as well as calculated fields like 
> total_fees, total_paid_fees, remaining_fees etc. 'Student_payments' would 
> only carry number of payments over the periods. When you have this 
> structure ready then you can think of maintaining totals in parent table 
> per student.
>
>  
>
> anyways, to your question following line would not work in save() method
>
> >>> self.paid_fees = *student*.fee_set.aggregate(*total_paid_fees*
> =sum('paid_fees'))  
>
>  
>
> since you don't have 
>
> >>> *student* = Student.objects.get(id=pk)
>
>  
>
> even if you want to save then which record in the table would you 
> update... so logically its wrong.
>
>  
>
> On Tuesday, September 15, 2020 at 2:04:57 AM UTC-4 dex9...@gmail.com 
> wrote:
>
> *def* save(*self*, **args*, ***kwargs*):
>
> self.paid_fees = student.fee_set.aggregate(*total_paid_fees*=sum(
> 'paid_fees'))
>
> self.school_fees = first_record.school_fees
>
> self.remaining_fees = self.school_fees - self.paid_fees
>
> if self.rema

Re: Help me with the view please

2020-09-21 Thread coolguy
yes you will... I left these for you... but definitely you can write me. 

On Monday, September 21, 2020 at 2:58:14 PM UTC-4 dex9...@gmail.com wrote:

> Hi @coolguy, thanks for your attachments,  have created all the views and 
> templates, and I have been working on them for my new web app, for this new 
> models will it be easy for more implement or auto check paid all checkbox 
> all payments have been completed, please, how?
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Thursday, September 17, 2020 6:26 AM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> If you are using sqllite3 then make a copy of it and delete the existing 
> sqllite3 file from your project. Keep the old file as you may need it.
>
>  
>
> Here are project files... i quickly make them but these are working..
>
>  
>
>  
>
>  
>
>  
>
> On Wednesday, September 16, 2020 at 3:57:22 PM UTC-4 dex9...@gmail.com 
> wrote:
>
> Since model design is where I very much struggle, and I think  my fee 
> management system models are not well design, so I need your help in 
> redesigning my models please
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Wednesday, September 16, 2020 5:31 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> There are a lot of courses but those are very basic and keep on talking 
> about same thing that you might have learned before... even after taking 
> courses you will have to think yourself how to structure your tables
>
>  
>
> I would suggest don't start any big project rather start with a simple 
> Student, Payment and Class models. Keep master information in your Student 
> and class models and all transaction in Payment model.
>
>  
>
> I can help you in designing the models.
>
>  
>
> Let me know...
>
>  
>
> On Wednesday, September 16, 2020 at 12:43:06 AM UTC-4 dex9...@gmail.com 
> wrote:
>
> Thanks for your valuable information, it seems my models are not well 
> constructed, I will first work on them.
>
> Don’t you have a YouTube channel or website or paid course somewhere like 
> Udemy where I can learn more
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Tuesday, September 15, 2020 10:57 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> Isn't this 'paid_fee' used to record the quarterly/monthly payments from 
> students? and this field will have multiple records? 
>
>  
>
> It seems you are looking to save an accumulated paid_fee (total_paid_fees) 
> somewhere in table. 
>
> If i am corrected then... this type of structure is okay when you are 
> working on spreadsheet solution e.g. microsoft excel, and save/calculate 
> the result in a separate column for the user info but when we deal with the 
> database and UI solution we don't use this approach... rather we show such 
> calculation on template. We persist initial setup values like student name, 
> school_fees etc and the recurring transactions in database.
>
>  
>
> If you really want to save this type of information in your database you 
> get to change your database structure and create a parent and child 
> relationship between Fee (being parent) and Student_Payments (being child). 
> 'Fee' would have all setup information as well as calculated fields like 
> total_fees, total_paid_fees, remaining_fees etc. 'Student_payments' would 
> only carry number of payments over the periods. When you have this 
> structure ready then you can think of maintaining totals in parent table 
> per student.
>
>  
>
> anyways, to your question following line would not work in save() method
>
> >>> self.paid_fees = *student*.fee_set.aggregate(*total_paid_fees*
> =sum('paid_fees'))  
>
>  
>
> since you don't have 
>
> >>> *student* = Student.objects.get(id=pk)
>
>  
>
> even if you want to save then which record in the table would you 
> update... so logically its wrong.
>
>  
>
> On Tuesday, September 15, 2020 at 2:04:57 AM UTC-4 dex9...@gmail.com 
> wrote:
>
> *def* save(*self*, **args*, ***kwargs*):
>
> self.paid_fees = student.fee_set.aggregate(*total_paid_fees*=sum(
> 'paid_fees'))
>
> self.school_fees = first_record.school_fees
>
> self.remaining_fees = self.school_fees - self.paid_fees
>
> if s

Re: Help me with the view please

2020-09-21 Thread coolguy
yes you will... I left these for you... but definitely you can write me 
directly @ naseem.pyt...@gmail.com


On Monday, September 21, 2020 at 2:58:14 PM UTC-4 dex9...@gmail.com wrote:

> Hi @coolguy, thanks for your attachments,  have created all the views and 
> templates, and I have been working on them for my new web app, for this new 
> models will it be easy for more implement or auto check paid all checkbox 
> all payments have been completed, please, how?
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Thursday, September 17, 2020 6:26 AM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> If you are using sqllite3 then make a copy of it and delete the existing 
> sqllite3 file from your project. Keep the old file as you may need it.
>
>  
>
> Here are project files... i quickly make them but these are working..
>
>  
>
>  
>
>  
>
>  
>
> On Wednesday, September 16, 2020 at 3:57:22 PM UTC-4 dex9...@gmail.com 
> wrote:
>
> Since model design is where I very much struggle, and I think  my fee 
> management system models are not well design, so I need your help in 
> redesigning my models please
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Wednesday, September 16, 2020 5:31 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> There are a lot of courses but those are very basic and keep on talking 
> about same thing that you might have learned before... even after taking 
> courses you will have to think yourself how to structure your tables
>
>  
>
> I would suggest don't start any big project rather start with a simple 
> Student, Payment and Class models. Keep master information in your Student 
> and class models and all transaction in Payment model.
>
>  
>
> I can help you in designing the models.
>
>  
>
> Let me know...
>
>  
>
> On Wednesday, September 16, 2020 at 12:43:06 AM UTC-4 dex9...@gmail.com 
> wrote:
>
> Thanks for your valuable information, it seems my models are not well 
> constructed, I will first work on them.
>
> Don’t you have a YouTube channel or website or paid course somewhere like 
> Udemy where I can learn more
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Tuesday, September 15, 2020 10:57 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> Isn't this 'paid_fee' used to record the quarterly/monthly payments from 
> students? and this field will have multiple records? 
>
>  
>
> It seems you are looking to save an accumulated paid_fee (total_paid_fees) 
> somewhere in table. 
>
> If i am corrected then... this type of structure is okay when you are 
> working on spreadsheet solution e.g. microsoft excel, and save/calculate 
> the result in a separate column for the user info but when we deal with the 
> database and UI solution we don't use this approach... rather we show such 
> calculation on template. We persist initial setup values like student name, 
> school_fees etc and the recurring transactions in database.
>
>  
>
> If you really want to save this type of information in your database you 
> get to change your database structure and create a parent and child 
> relationship between Fee (being parent) and Student_Payments (being child). 
> 'Fee' would have all setup information as well as calculated fields like 
> total_fees, total_paid_fees, remaining_fees etc. 'Student_payments' would 
> only carry number of payments over the periods. When you have this 
> structure ready then you can think of maintaining totals in parent table 
> per student.
>
>  
>
> anyways, to your question following line would not work in save() method
>
> >>> self.paid_fees = *student*.fee_set.aggregate(*total_paid_fees*
> =sum('paid_fees'))  
>
>  
>
> since you don't have 
>
> >>> *student* = Student.objects.get(id=pk)
>
>  
>
> even if you want to save then which record in the table would you 
> update... so logically its wrong.
>
>  
>
> On Tuesday, September 15, 2020 at 2:04:57 AM UTC-4 dex9...@gmail.com 
> wrote:
>
> *def* save(*self*, **args*, ***kwargs*):
>
> self.paid_fees = student.fee_set.aggregate(*total_paid_fees*=sum(
> 'paid_fees'))
>
> self.school_fees = first_record.school_fees
>
> self.remaining_fees = self.school_fees - self.

Re: How to Add to Django Administration Using Code

2020-09-21 Thread coolguy

further to my previous comments please share the your related model code to 
make discussion interesting...
On Sunday, September 20, 2020 at 11:35:05 AM UTC-4 Lightning Bit wrote:

> Hi all, 
>
> I am trying to figure out how to add "Customers" using code. Please look 
> at the administration layout: 
>
> [image: HELP.png]
>
> I was able to add to "Groups" using the following code in "views.py": 
>
> *@unauthenticated_user*
> *def registerPage(request):*
>
> *form = CreateUserForm()*
>
> *if request.method == 'POST':*
> *form = CreateUserForm(request.POST)*
> *if form.is_valid():*
> *user = form.save()*
> *username = form.cleaned_data.get('username')*
> 
> *group = Group.objects.get(name='customer')*
> *user.groups.add(group)*
> 
>
>
>
> *messages.success(request, 'BOLT Force account was 
> created for' + username )*
> *return redirect('login')*
>
> *data= cartData(request)*
>
> *items=data['items']*
> *order=data['order']*
> *cartItems=data['cartItems']*
>
> *products = Product.objects.all()*
>
> *context = {'products':products, 'items':items, 'order':order, 
> 'cartItems':cartItems, 'form':form}*
> *return render(request, 'store/register.html', context)*
>
> However, I am unsure of how to add to the "Customers" section of the 
> picture above. I have tried almost every technique with no luck. I wanted 
> both the "Groups" and the "Customers" to have the same registered person 
> added at once. Would anyone happen to know how to fix this? 
>
> Thank you!
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/76689278-42d6-4fbf-83d1-248b2a9721b8n%40googlegroups.com.


Re: How to Add to Django Administration Using Code

2020-09-21 Thread coolguy
do want to add the picture file to the customer application or want to see 
the picture in admin?

On Sunday, September 20, 2020 at 11:35:05 AM UTC-4 Lightning Bit wrote:

> Hi all, 
>
> I am trying to figure out how to add "Customers" using code. Please look 
> at the administration layout: 
>
> [image: HELP.png]
>
> I was able to add to "Groups" using the following code in "views.py": 
>
> *@unauthenticated_user*
> *def registerPage(request):*
>
> *form = CreateUserForm()*
>
> *if request.method == 'POST':*
> *form = CreateUserForm(request.POST)*
> *if form.is_valid():*
> *user = form.save()*
> *username = form.cleaned_data.get('username')*
> 
> *group = Group.objects.get(name='customer')*
> *user.groups.add(group)*
> 
>
>
>
> *messages.success(request, 'BOLT Force account was 
> created for' + username )*
> *return redirect('login')*
>
> *data= cartData(request)*
>
> *items=data['items']*
> *order=data['order']*
> *cartItems=data['cartItems']*
>
> *products = Product.objects.all()*
>
> *context = {'products':products, 'items':items, 'order':order, 
> 'cartItems':cartItems, 'form':form}*
> *return render(request, 'store/register.html', context)*
>
> However, I am unsure of how to add to the "Customers" section of the 
> picture above. I have tried almost every technique with no luck. I wanted 
> both the "Groups" and the "Customers" to have the same registered person 
> added at once. Would anyone happen to know how to fix this? 
>
> Thank you!
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/91e61ad8-1a47-4b73-b0cf-7053056e6a21n%40googlegroups.com.


Re: Inline Formset

2020-09-19 Thread coolguy
Please share some code so we can look into.

On Friday, September 18, 2020 at 12:50:49 AM UTC-4 lada...@gmail.com wrote:

> Good day friends, Please i have a small challenge, I have an inline 
> formset in my admin where users can add more products to a store. The user 
> can also add a product if It doesn’t already exist. The problem is when the 
> user adds a new product and wants to add more product fields to the Store 
> model the product the user added doesn’t show in the dropdown of the new 
> field unless i refresh the whole interface. Please any way to fix this. 
> Thanks
>
> From Ntiamoah 
>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5bbf293f-a9fb-4bfd-b3d3-745e1ee2486fn%40googlegroups.com.


Re: Calculated feild in models

2020-09-19 Thread coolguy
Create a function at class level like this..

*class xxx(models.Model):*
quantity = models.FloatField()
unit_price = models.FloatField()

   * def get_total_price(self):*
 return self.quantity * self.unit_price


On Saturday, September 19, 2020 at 11:15:30 AM UTC-4 eankomah wrote:

> I have two fields: 
> quantity = models.FloatField()
> unit_price = models.FloatField()
>
> and i want ot do someting like this
>
>
> total_price = models.FloatField('unit_price' * 'quantity')
>
> 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/daa1a5d0-1266-49fa-a453-ceaa5f7785fcn%40googlegroups.com.


Re: how to create url helloworld

2020-09-19 Thread coolguy
Instead of 
from pages import views  

use
from . import views
On Saturday, September 19, 2020 at 11:15:34 AM UTC-4 leoa...@gmail.com 
wrote:

> *file views.py in folder pages
>
> from django.htpp import HtppResponse
> from django.shortcuts import render
>
> # Create your views here.
> def home_view(*args, **kwargs): # *args, **kwargs
> return HtppResponse("hello world")  
>
>
> C:\Users\leo>C:/python37/python.exe 
> c:/python37/Try-Django-master/src/pages/views.py
> Traceback (most recent call last):
>   File "c:/python37/Try-Django-master/src/pages/views.py", line 1, in 
> 
> from django.htpp import HtppResponse
> ModuleNotFoundError: No module named 'django.htpp'
>
> from django.htpp import HtppResponse
> from django.shortcuts import render
>
> *files urls.py 
>
> from django.contrib import admin
> from django.urls import path
>
> from pages import views
>
> urlpatterns = [
> path('', views.home_view, name='home'),
> path('admin/', admin.site.urls),
> ]
>
> file setting
> INSTALLED_APPS = [
> 'django.contrib.admin',
> 'django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.messages',
> 'django.contrib.staticfiles',
>
> # third party
> # own
> 'pages',
> 'products',
> ]
>
> error :   
> File "C:\python37\Try-Django-master\src\trydjango\urls.py", line 19, in 
> 
> from pages import views
>   File "C:\python37\Try-Django-master\src\pages\views.py", line 1, in 
> 
> from django.htpp import HtppResponse
> ModuleNotFoundError: No module named 'django.htpp'
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/64c882b9-9ab4-49a5-9a72-347cdadd324dn%40googlegroups.com.


Re: TypeError: object() takes No Parameters

2020-09-17 Thread coolguy
The error lies in the following line

>>>  queryset = monthlyCostTable(getMonthlyCostQuery(2020, 'region')) 

Your class monthlyCostTable does not take any parameter while you are 
passing getMonthlyCost... you know better what your doing but this line is 
the root cause...
 

On Thursday, September 17, 2020 at 4:00:08 PM UTC-4 pcar...@gmail.com wrote:

> The actual trace coolguy is 
>
> TypeError at /functions/ClassMonthlyCost/object() takes no 
> parametersRequest 
> Method: GETRequest 
> URL: http://98.8.61.133:8080/functions/ClassMonthlyCost/Django 
> Version: 2.2.4Exception 
> Type: TypeErrorException 
> Value: object() takes no parametersException 
> Location: 
> /home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/django/core/handlers/base.py
>  
> in _get_response, line 113Python 
> Executable: /home/db_user/ciopsdb/venv/bin/pythonPython 
> Version:3.6.8
> Python Path:
> ['/home/db_user/ciopsdb', '/usr/lib64/python36.zip', 
> '/usr/lib64/python3.6', '/usr/lib64/python3.6/lib-dynload', 
> '/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages', 
> '/home/db_user/ciopsdb/venv/lib/python3.6/site-packages', 
> '/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/odf', 
> '/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/odf', 
> '/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/odf', 
> '/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/odf', 
> '/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/odf', 
> '/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/odf', 
> '/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/odf']
> Server time: Thu, 17 Sep 2020 18:29:52 +  
>
> On Thursday, September 17, 2020 at 2:26:32 PM UTC-5 coolguy wrote:
>
>> is there any specific line number that message is pointing too. Can you 
>> share the actual error message and its trace...
>>
>> On Thursday, September 17, 2020 at 2:35:53 PM UTC-4 pcar...@gmail.com 
>> wrote:
>>
>>> Hello everyone, I am trying to utilize the SIngleTableMixin of 
>>> django_tables2 using a custom function that queries my database and 
>>> aggregates the data into a list of dictionaries.  I read to use the 
>>> SingleTableMixin that all I needed was an iterable containing a data 
>>> structure that has a key(a list of dicts) and then to instantiate a table 
>>> in tables.py and pass to a my views Class.  I am getting an error when I do 
>>> this TypeError: Object() takes no parameters.  I have included a link to 
>>> the django tables 2 doc and my code below:
>>>
>>> #views.py
>>> from django_tables2.views import SingleTableMixin
>>> from django_tables2.export.views import ExportMixin
>>> from django_filters.views import FilterView
>>> from django.views.generic.list import ListView
>>> from django.shortcuts import render
>>>
>>> from finance.models import Circuitinfotable, Budget
>>> from .forms import monthlyCostForm
>>> from .tables import CircuitTable, monthlyCostTable
>>> from .filters import CircuitinfotableFilter
>>>
>>> from datetime import datetime
>>> from decimal import Decimal
>>> from re import sub
>>> import calendar
>>>
>>> #convert a distinct queryset into a singular list of values
>>> def getList(qs, key):
>>> resultsList = []
>>> for each in qs:
>>> resultsList.append(each[key])
>>> return resultsList
>>>
>>>
>>> def getDistinct(key):
>>> return Circuitinfotable.objects.all().values(key).distinct()
>>>
>>>
>>> def convertCurrency(val):
>>> return Decimal(sub(r'[^\d.]', '', val))
>>>
>>>
>>> def getMonthlyCostQuery(year, field):
>>> circuits = Circuitinfotable.objects.all()
>>> field_list = getList(getDistinct(field), field)
>>>
>>> results_list = []
>>> resultsDict={'field': 'None', 'Jan': 0, 'Feb': 0, 'Mar': 0, 'Apr': 
>>> 0, 'May': 0, 'Jun': 0, 'Jul': 0, 'Aug': 0, 'Sep': 0, 'Oct': 0, 'Nov': 0, 
>>> 'Dec': 0,
>>>  'Janbw': 0, 'Febbw': 0, 'Marbw': 0, 'Aprbw': 0, 
>>> 'Maybw': 0, 'Junbw': 0, 'Julbw': 0, 'Augbw': 0, 'Sepbw': 0, 'Octbw': 0, 
>>> 'Novbw': 0, 'Decbw': 0}
>>> results_list.append(resultsDict)
>>> for each in field_list:
>>> if each!=None and each!='None':
>>> resultsDict={'field': '', 'Jan': 0, 'Feb': 0, 'Mar': 0, 
>>> 'Apr': 0, 'May': 0, 'Jun': 0, 'Jul': 0, 'Aug': 0, 'Sep': 0, 'Oct': 0, 
>>> 'Nov': 0,

Re: TypeError: object() takes No Parameters

2020-09-17 Thread coolguy
is there any specific line number that message is pointing too. Can you 
share the actual error message and its trace...

On Thursday, September 17, 2020 at 2:35:53 PM UTC-4 pcar...@gmail.com wrote:

> Hello everyone, I am trying to utilize the SIngleTableMixin of 
> django_tables2 using a custom function that queries my database and 
> aggregates the data into a list of dictionaries.  I read to use the 
> SingleTableMixin that all I needed was an iterable containing a data 
> structure that has a key(a list of dicts) and then to instantiate a table 
> in tables.py and pass to a my views Class.  I am getting an error when I do 
> this TypeError: Object() takes no parameters.  I have included a link to 
> the django tables 2 doc and my code below:
>
> #views.py
> from django_tables2.views import SingleTableMixin
> from django_tables2.export.views import ExportMixin
> from django_filters.views import FilterView
> from django.views.generic.list import ListView
> from django.shortcuts import render
>
> from finance.models import Circuitinfotable, Budget
> from .forms import monthlyCostForm
> from .tables import CircuitTable, monthlyCostTable
> from .filters import CircuitinfotableFilter
>
> from datetime import datetime
> from decimal import Decimal
> from re import sub
> import calendar
>
> #convert a distinct queryset into a singular list of values
> def getList(qs, key):
> resultsList = []
> for each in qs:
> resultsList.append(each[key])
> return resultsList
>
>
> def getDistinct(key):
> return Circuitinfotable.objects.all().values(key).distinct()
>
>
> def convertCurrency(val):
> return Decimal(sub(r'[^\d.]', '', val))
>
>
> def getMonthlyCostQuery(year, field):
> circuits = Circuitinfotable.objects.all()
> field_list = getList(getDistinct(field), field)
>
> results_list = []
> resultsDict={'field': 'None', 'Jan': 0, 'Feb': 0, 'Mar': 0, 'Apr': 0, 
> 'May': 0, 'Jun': 0, 'Jul': 0, 'Aug': 0, 'Sep': 0, 'Oct': 0, 'Nov': 0, 
> 'Dec': 0,
>  'Janbw': 0, 'Febbw': 0, 'Marbw': 0, 'Aprbw': 0, 'Maybw': 
> 0, 'Junbw': 0, 'Julbw': 0, 'Augbw': 0, 'Sepbw': 0, 'Octbw': 0, 'Novbw': 0, 
> 'Decbw': 0}
> results_list.append(resultsDict)
> for each in field_list:
> if each!=None and each!='None':
> resultsDict={'field': '', 'Jan': 0, 'Feb': 0, 'Mar': 0, 'Apr': 
> 0, 'May': 0, 'Jun': 0, 'Jul': 0, 'Aug': 0, 'Sep': 0, 'Oct': 0, 'Nov': 0, 
> 'Dec': 0,
>  'Janbw': 0, 'Febbw': 0, 'Marbw': 0, 'Aprbw': 0, 
> 'Maybw': 0, 'Junbw': 0, 'Julbw': 0, 'Augbw': 0, 'Sepbw': 0, 'Octbw': 0, 
> 'Novbw': 0, 'Decbw': 0}
> resultsDict['field'] = each
> results_list.append(resultsDict)
>
> for circuit in circuits:
> #If you add a field to forms.py to aggregate by then add here
> if field=='region':
> matchField = circuit.region
> elif field=='carrier':
> matchField = circuit.carrier
> elif field=='bandwidth':
> matchField = circuit.bandwidth
> elif field=='status':
> matchField = circuit.status
> #get the budget for each circuit
> for budgetItem in circuit.budget_set.filter(yearnum=year):
> #if an item is budgeted for given month
> if(budgetItem.actualmrc!=0):
> #Cycle through results_list to find the correct dictionary
> for each in results_list:
> if each['field']==matchField:
> #update budgetItem and bw
> if budgetItem != None:
> 
> each[calendar.month_abbr[budgetItem.monthnum]]+=convertCurrency(budgetItem.actualmrc)
> if circuit.bw!= None:
> each[calendar.month_abbr[budgetItem.monthnum] 
> + 'bw']+=int(circuit.bw)
> elif matchField==None:
> if budgetItem != None:
> 
> results_list[0][calendar.month_abbr[budgetItem.monthnum]]+=convertCurrency(budgetItem.actualmrc)
> if circuit.bw!= None:
> 
> results_list[0][calendar.month_abbr[budgetItem.monthnum]+'bw']+=int(
> circuit.bw)
>
> results_list = sorted(results_list, key=lambda i:i['field'])
> return results_list
>
>
> class MonthlyCost(SingleTableMixin):
> template_name = 'functions/ClassMonthlyCost.html'
> context_object_name = 'qs'
> queryset = monthlyCostTable(getMonthlyCostQuery(2020, 'region'))
>
>
> #tables.py
> import django_tables2 as tables
> from django_tables2.utils import A
> from .models import Circuitinfotable
>
> class CircuitTable(tables.Table):
> class Meta:
> model = Circuitinfotable
> export_formats = ['csv', 'xlsx']
> template_name = "django_tables2/bootstrap.html"
> Id1 = tables.Column(linkify={"viewname": "viewLit", "args": 
> [tables.A('id1__pk')]})
> 

Re: FieldError regarding custom User model which overrides the default auth User model

2020-09-16 Thread coolguy
Could not go through all your attachments but just reviewed few line of 
your models.py...

just my two cents... If you are going to use email for your login then 
USERNAME_FIELD should carry email not username...

USERNAME_FIELD = 'email'

On Wednesday, September 16, 2020 at 5:02:35 PM UTC-4 johnre...@gmail.com 
wrote:

> In my project I have two apps. Both of these apps require the *email* 
> field not to be blank and one of those apps doesn't need the *first_name* 
> and the *last_name* fields, so I decided to override the default *User* 
> class available from *django.contrib.auth.models*. I did it following this 
> 
>  
> guide. 
>
> Here you can find the models.py  file for the 
> app where my new User class is defined, as well as the settings.py 
>  code for my overall project (in the end of the 
> file I define *AUTH_USER_MODEL*). As the guide I linked in the above 
> paragraph suggests, I modified the admin.py  
> file as well.
>
> I updated the models.py  file of my other app to 
> use the project-wide *AUTH_USER_MODEL* as well.
>
> However, when I try to add a new user via the admin interface, I get an 
> error saying *FieldError at /admin/employers/user/8/change/ Unknown 
> field(s) (first_name, last_name) specified for User. Check 
> fields/fieldsets/exclude attributes of class UserAdmin*. Here's the 
> traceback: https://dpaste.org/osxj
>
> I'm not sure what is going wrong here. I followed the guide here 
>  in its 
> entirety (you can see that from my admin.py file), but I still get the 
> error. *What is going on here? How do I fix this error?*
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7005e5d0-367a-45e7-8650-5d95dae4a4d0n%40googlegroups.com.


Re: Help me with the view please

2020-09-16 Thread coolguy
If you are using sqllite3 then make a copy of it and delete the existing 
sqllite3 file from your project. Keep the old file as you may need it.

Here are project files... i quickly make them but these are working...





On Wednesday, September 16, 2020 at 3:57:22 PM UTC-4 dex9...@gmail.com 
wrote:

> Since model design is where I very much struggle, and I think  my fee 
> management system models are not well design, so I need your help in 
> redesigning my models please
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Wednesday, September 16, 2020 5:31 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> There are a lot of courses but those are very basic and keep on talking 
> about same thing that you might have learned before... even after taking 
> courses you will have to think yourself how to structure your tables
>
>  
>
> I would suggest don't start any big project rather start with a simple 
> Student, Payment and Class models. Keep master information in your Student 
> and class models and all transaction in Payment model.
>
>  
>
> I can help you in designing the models.
>
>  
>
> Let me know...
>
>  
>
> On Wednesday, September 16, 2020 at 12:43:06 AM UTC-4 dex9...@gmail.com 
> wrote:
>
> Thanks for your valuable information, it seems my models are not well 
> constructed, I will first work on them.
>
> Don’t you have a YouTube channel or website or paid course somewhere like 
> Udemy where I can learn more
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Tuesday, September 15, 2020 10:57 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> Isn't this 'paid_fee' used to record the quarterly/monthly payments from 
> students? and this field will have multiple records? 
>
>  
>
> It seems you are looking to save an accumulated paid_fee (total_paid_fees) 
> somewhere in table. 
>
> If i am corrected then... this type of structure is okay when you are 
> working on spreadsheet solution e.g. microsoft excel, and save/calculate 
> the result in a separate column for the user info but when we deal with the 
> database and UI solution we don't use this approach... rather we show such 
> calculation on template. We persist initial setup values like student name, 
> school_fees etc and the recurring transactions in database.
>
>  
>
> If you really want to save this type of information in your database you 
> get to change your database structure and create a parent and child 
> relationship between Fee (being parent) and Student_Payments (being child). 
> 'Fee' would have all setup information as well as calculated fields like 
> total_fees, total_paid_fees, remaining_fees etc. 'Student_payments' would 
> only carry number of payments over the periods. When you have this 
> structure ready then you can think of maintaining totals in parent table 
> per student.
>
>  
>
> anyways, to your question following line would not work in save() method
>
> >>> self.paid_fees = *student*.fee_set.aggregate(*total_paid_fees*
> =sum('paid_fees'))  
>
>  
>
> since you don't have 
>
> >>> *student* = Student.objects.get(id=pk)
>
>  
>
> even if you want to save then which record in the table would you 
> update... so logically its wrong.
>
>  
>
> On Tuesday, September 15, 2020 at 2:04:57 AM UTC-4 dex9...@gmail.com 
> wrote:
>
> *def* save(*self*, **args*, ***kwargs*):
>
> self.paid_fees = student.fee_set.aggregate(*total_paid_fees*=sum(
> 'paid_fees'))
>
> self.school_fees = first_record.school_fees
>
> self.remaining_fees = self.school_fees - self.paid_fees
>
> if self.remaining_fees == 0:
>
> self.completed = True
>
> else:
>
> self.completed = False
>
> 
>
> *super*().save(*args, **kwargs)
>
> I have tried doing it like this, perhaps maybe you can see what I’m trying 
> to do
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986>
>
>  
>
> *From: *coolguy
> *Sent: *Monday, September 14, 2020 11:53 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> not sure what are you looking for.. but based on your model setup... 
> school fees is setup once so we picked it up from first object/record from 
> table, while paid fees are collected quarterly or whatever means there will 
> be more than on

Re: How to calculate appreciation in django

2020-09-16 Thread coolguy
Did you setup the limits and maintenance dates in your asset models?

If yes, then did you create any view that is available to designated user 
who can run that report to see what is due for maintenance and re-ordering.

Please share more detail..

On Wednesday, September 16, 2020 at 12:03:56 PM UTC-4 ernes...@gmail.com 
wrote:

> This is an example of a reorder level function in views.py
> def reorder_level(request, pk):
> queryset = Asset.objects.get(id=pk)
> form = ReorderLevelForm(request.POST or None, instance=queryset)
> if form.is_valid():
> instance = form.save(commit=False)
> instance.save()
> messages.success(request, "Reorder level for " + str(instance.item_name) + 
> " is updated to " + str(instance.reorder_level))
> return redirect("list_items")
> context = {
>"instance": queryset,
>"form": form,
> }
> return render(request, "add_items.html", context)
>
> On Wed, Sep 16, 2020 at 6:58 PM Ernest Thuku  wrote:
>
>> The system is a managing system whereby you maage Items like the stock 
>> system, this one manages assets likes furniters,computers etc. The item is 
>> added in the system and the system can be able to offer an alert when a 
>> certain item is below where the reorder level is. The system can also be 
>> able to alert on maintenance dates whereby after a certain period it alerts 
>> it need to be maintained. I wanted to add a functionality whereby the 
>> system can be able to calculate either depreciation or appreciation on the 
>> asset.
>>
>>
>> On Wed, Sep 16, 2020 at 6:47 PM Akorede Habeebullah  
>> wrote:
>>
>>> Can you be more elaborate?
>>> How does the system work?
>>>
>>> *Akorede Habeebullah A.*
>>> *hda...@gmail.com*
>>> *+2348179564316 <+234%20817%20956%204316>*
>>>
>>>
>>> On Wed, Sep 16, 2020 at 4:43 PM Ernest Thuku  wrote:
>>>
 Hello guys,
 I have developed a system to manage assets. It is more like a stock 
 management system whereby the system has a reorder level and such. Anyone 
 who can help me to apply appreciation/depreciation code?

 -- 
 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 view this discussion on the web visit 
 https://groups.google.com/d/msgid/django-users/CAPsfuoeLeeXJx3ZGA8X8vD3t1W7CYb3xi2t9%2BLUqXpdFuHD_0Q%40mail.gmail.com
  
 
 .

>>> -- 
>>> 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 view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/CAK37-gO5qosxEpK7ULb9GxCfBq4ky2MYqOf_7WkDCxQBo%2BiZBQ%40mail.gmail.com
>>>  
>>> 
>>> .
>>>
>>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2d47a010-e347-4d2a-8ac4-416fa89ff815n%40googlegroups.com.


Re: Help me with the view please

2020-09-16 Thread coolguy
There are a lot of courses but those are very basic and keep on talking 
about same thing that you might have learned before... even after taking 
courses you will have to think yourself how to structure your tables

I would suggest don't start any big project rather start with a simple 
Student, Payment and Class models. Keep master information in your Student 
and class models and all transaction in Payment model.

I can help you in designing the models.

Let me know...

On Wednesday, September 16, 2020 at 12:43:06 AM UTC-4 dex9...@gmail.com 
wrote:

> Thanks for your valuable information, it seems my models are not well 
> constructed, I will first work on them.
>
> Don’t you have a YouTube channel or website or paid course somewhere like 
> Udemy where I can learn more
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Tuesday, September 15, 2020 10:57 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> Isn't this 'paid_fee' used to record the quarterly/monthly payments from 
> students? and this field will have multiple records? 
>
>  
>
> It seems you are looking to save an accumulated paid_fee (total_paid_fees) 
> somewhere in table. 
>
> If i am corrected then... this type of structure is okay when you are 
> working on spreadsheet solution e.g. microsoft excel, and save/calculate 
> the result in a separate column for the user info but when we deal with the 
> database and UI solution we don't use this approach... rather we show such 
> calculation on template. We persist initial setup values like student name, 
> school_fees etc and the recurring transactions in database.
>
>  
>
> If you really want to save this type of information in your database you 
> get to change your database structure and create a parent and child 
> relationship between Fee (being parent) and Student_Payments (being child). 
> 'Fee' would have all setup information as well as calculated fields like 
> total_fees, total_paid_fees, remaining_fees etc. 'Student_payments' would 
> only carry number of payments over the periods. When you have this 
> structure ready then you can think of maintaining totals in parent table 
> per student.
>
>  
>
> anyways, to your question following line would not work in save() method
>
> >>> self.paid_fees = *student*.fee_set.aggregate(*total_paid_fees*
> =sum('paid_fees'))  
>
>  
>
> since you don't have 
>
> >>> *student* = Student.objects.get(id=pk)
>
>  
>
> even if you want to save then which record in the table would you 
> update... so logically its wrong.
>
>  
>
> On Tuesday, September 15, 2020 at 2:04:57 AM UTC-4 dex9...@gmail.com 
> wrote:
>
> *def* save(*self*, **args*, ***kwargs*):
>
> self.paid_fees = student.fee_set.aggregate(*total_paid_fees*=sum(
> 'paid_fees'))
>
> self.school_fees = first_record.school_fees
>
> self.remaining_fees = self.school_fees - self.paid_fees
>
> if self.remaining_fees == 0:
>
> self.completed = True
>
> else:
>
> self.completed = False
>
> 
>
> *super*().save(*args, **kwargs)
>
> I have tried doing it like this, perhaps maybe you can see what I’m trying 
> to do
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986>
>
>  
>
> *From: *coolguy
> *Sent: *Monday, September 14, 2020 11:53 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> not sure what are you looking for... but based on your model setup... 
> school fees is setup once so we picked it up from first object/record from 
> table, while paid fees are collected quarterly or whatever means there will 
> be more than one transaction in fee table. We have already calculated the 
> "paid_fees" from fee table like this
>
> >>>  
>   paid_fees = student.fee_set.aggregate(total_paid_fees=Sum('paid_fees'))
>
>  
>
> I definitely want to help as long as i know what you are looking for :)
>
>  
>
>  
>
> On Monday, September 14, 2020 at 4:26:48 PM UTC-4 dex9...@gmail.com wrote:
>
> Thanks it has worked, but it doesn’t work with my total_paid_fees, I want 
> to be automatically checked when school_fees substracts summation of all 
> paid_fees, just like this solution you provided me with the last time
>
> first_record = student.fee_set.first()
>
>  school_fees = first_record.school_fees
>
>   paid_fees = student.fee_set.aggregate(total_paid_fees=Sum('paid_fees'))
>
>balance_fees =  school_fees - paid_fees["tota

Re: HTML5 drag and drop: How does it really work?

2020-09-15 Thread coolguy
Are you saving these players in database with their present slot ids etc. 
they are in? It seems easy solution if we can update their present slot 
info after dnd in the database table and filter the templates based on the 
slot ids.


On Tuesday, September 15, 2020 at 2:23:17 PM UTC-4 Elliot wrote:

> Thanks Coolguy.  Your answer is the first one getting close to what I am 
> looking for.  I have a similar situation to the one you described.  I 
> have 2 timeslots slot A and Slot B.  Slot A might represent 10:00am on 
> 09/15 and slot B  11:00AM on 9/16.  These slots have been chosen from a 
> list of all time slots for the week.  The user goes down the list of all 
> time slots and selects a time for slot A and another for slot B.  This in 
> turn populates a list of all players in each slot.  The user may then 
> drag a player name from slot A to slot B or vice versa.  This works great 
> visually, but doesn't do anything else.
>
>  In the html each player in a slot is represented by a row in a table.  The 
> slot A table and the slot B table are each within their own div and part of 
> the same form.
>
>  So the form is something like this:
>
>  
>
>
>
>  ="id_Aplayerstable" name ="Aplayerstable" > 
>
>="Aid_tbody"  ondragover="allowdrop(event)" ondrop="drop(event)" 
> contenteditable ="true">
>
>   
>
> {% for player in Aplayers %}   
>
>  tabindex="0" id="{{forloop.counter0}}Aid_tr" style="width:100%;" 
> contenteditable ="true" draggable="true"  
>  
>   ondragstart="dragstart(event)"  >
>
> 
>
>   
> 
>  contenteditable ="true" > 
>
>   
>   
>  readonly value="{{player.status}}"
>   
>
> style="display:none; " 
>
>   
> 
>id="{{forloop.counter0}}Aid_playerid "name ="Aplayerid" 
> value="{{player.Player_id}}" 
>
>   
>   
>   style ="display: none;" contenteditable ="true"
>
>   
> 
>id="{{forloop.counter0}}Aid_username" name ="Ausername"   
>
>   
> 
>   readonly value="{{player.username}}" style="width: 
> 90%;text-align : center;  
>
>   
> 
> background-color:cornflowerblue;  color:white; border-style:groove; 
> border-color:yellow; border:medium;   
>   
> 
> bordercollapse:separate;" 
> draggable ="false" ondrop="drop(event)"  ondragover="allowdrop(event)"
>   
>  
>   contenteditable="true"  
>
>   
> 
> 
>
> 
> 
>
> {% endfor %}   
>
>   
>
> 
>
>
>
>  
>
>   
>
> same as Aplayers except for the "*B*" 
> replacing "*A*" ids and names
>
>  

Re: Help me with the view please

2020-09-15 Thread coolguy
Isn't this 'paid_fee' used to record the quarterly/monthly payments from 
students? and this field will have multiple records? 

It seems you are looking to save an accumulated paid_fee (total_paid_fees) 
somewhere in table. 
If i am corrected then... this type of structure is okay when you are 
working on spreadsheet solution e.g. microsoft excel, and save/calculate 
the result in a separate column for the user info but when we deal with the 
database and UI solution we don't use this approach... rather we show such 
calculation on template. We persist initial setup values like student name, 
school_fees etc and the recurring transactions in database.

If you really want to save this type of information in your database you 
get to change your database structure and create a parent and child 
relationship between Fee (being parent) and Student_Payments (being child). 
'Fee' would have all setup information as well as calculated fields like 
total_fees, total_paid_fees, remaining_fees etc. 'Student_payments' would 
only carry number of payments over the periods. When you have this 
structure ready then you can think of maintaining totals in parent table 
per student.

anyways, to your question following line would not work in save() method
>>> self.paid_fees = *student*.fee_set.aggregate(*total_paid_fees*
=sum('paid_fees'))  

since you don't have 
>>> *student* = Student.objects.get(id=pk)

even if you want to save then which record in the table would you update... 
so logically its wrong.


On Tuesday, September 15, 2020 at 2:04:57 AM UTC-4 dex9...@gmail.com wrote:

> *def* save(*self*, **args*, ***kwargs*):
>
> self.paid_fees = student.fee_set.aggregate(*total_paid_fees*=sum(
> 'paid_fees'))
>
> self.school_fees = first_record.school_fees
>
> self.remaining_fees = self.school_fees - self.paid_fees
>
> if self.remaining_fees == 0:
>
> self.completed = True
>
> else:
>
> self.completed = False
>
> 
>
> *super*().save(*args, **kwargs)
>
> I have tried doing it like this, perhaps maybe you can see what I’m trying 
> to do
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986>
>
>  
>
> *From: *coolguy
> *Sent: *Monday, September 14, 2020 11:53 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> not sure what are you looking for... but based on your model setup... 
> school fees is setup once so we picked it up from first object/record from 
> table, while paid fees are collected quarterly or whatever means there will 
> be more than one transaction in fee table. We have already calculated the 
> "paid_fees" from fee table like this
>
> >>>  
>   paid_fees = student.fee_set.aggregate(total_paid_fees=Sum('paid_fees'))
>
>  
>
> I definitely want to help as long as i know what you are looking for :)
>
>  
>
>  
>
> On Monday, September 14, 2020 at 4:26:48 PM UTC-4 dex9...@gmail.com wrote:
>
> Thanks it has worked, but it doesn’t work with my total_paid_fees, I want 
> to be automatically checked when school_fees substracts summation of all 
> paid_fees, just like this solution you provided me with the last time
>
> first_record = student.fee_set.first()
>
>  school_fees = first_record.school_fees
>
>   paid_fees = student.fee_set.aggregate(total_paid_fees=Sum('paid_fees'))
>
>balance_fees =  school_fees - paid_fees["total_paid_fees"] 
>
>  
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Monday, September 14, 2020 9:09 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> Its simple... in your fee models' save method check that 
> self.remaining_fees is zero then make self.completed field to true... I 
> added else clause in case if admin make changes to paid fees and after 
> changes student still has some dues.
>
>  
>
> def save(self, *args, **kwargs):
>
>  
>
> self.remaining_fees = self.school_fees - self.paid_fees
>
> if self.remaining_fees == 0:
>
> self.completed = True
>
> else:
>
> self.completed = False
>
> 
>
> super().save(*args, **kwargs)
>
>  
>
> On Monday, September 14, 2020 at 7:11:51 AM UTC-4 dex9...@gmail.com wrote:
>
> Thank you brother @coolguy, I have put to work your latest solution and it 
> has worked like a charm.I have been learning a lot from you lately, as you 
> know i am still a beginner, i would love to learn one more thing from 
> you..i have a boolean field "completed",

Re: Environment Variables for Django Secret Key etc On Windows 10 and Heroku

2020-09-14 Thread coolguy
Did you input the variable value under single quote or without it?

e.g. ''

On Saturday, September 12, 2020 at 12:35:29 PM UTC-4 hanz...@gmail.com 
wrote:

> Yes, I've seen so many tutorials. I did the same thing, and didn't work. 
> I believe there is something wrong with my Django Project. I don't know 
> what it is.
> Still tinkering.
>
>
> On Sat, Sep 12, 2020 at 9:38 PM Mbah Victor  wrote:
>
>> Have you try googling your problem
>>
>> Victor
>>
>> On Sat, Sep 12, 2020, 9:34 AM dum dum  wrote:
>>
>>> I tried to put my Django Secret Key in Environment Variables.
>>>
>>> SECRET_KEY = os.environ.get('SECRET_KEY')
>>>
>>> I did save the SECRET_KEY on env var windows 10 like this
>>> [image: image.png]
>>>
>>>
>>> When I tried to py manage.py runserver, I got this error
>>>
>>> django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must 
>>> not be empty.
>>>
>>> I followed this 
>>>
>>> https://stackoverflow.com/questions/19681102/my-django-secret-key-is-in-an-environment-variable-but-i-cant-do-syncdb
>>>
>>> But no idea with the solution..
>>>
>>> At this point, strange thing even occurred, I tried to py manage.py 
>>> without any SECRET_KEY on my Env Var on windows 10, and just leaving 
>>>   SECRET_KEY = os.environ.get('SECRET_KEY') 
>>> in my settings.py.
>>>
>>> I got no error.
>>>
>>> Strange.. But when I deployed it on heroku, it says the same error like 
>>> this 
>>> django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting 
>>> must not be empty. 
>>>
>>> Is anyone here experienced the same stuck like me? Please kindly advise. 
>>> 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 view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/CANV3w%3DYdb3SuiC7KYrkN4bfieQx-fQxhm%2BPeMLpxJDWubVbwyA%40mail.gmail.com
>>>  
>>> 
>>> .
>>>
>> -- 
>> 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 view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CANTsAyc%3D%3DBLN7a0_c8rYd%3DsLHyWq78CHxAQr6Sa_PMcqtP7Cwg%40mail.gmail.com
>>  
>> 
>> .
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/11d60767-06d3-4d4c-8435-10151e5726cdn%40googlegroups.com.


Re: HTML5 drag and drop: How does it really work?

2020-09-14 Thread coolguy
The changes are done through script which you are doing at this time... the 
changes would only be visual for user and would not impact the source code.

following may be irrelevant for you but i would add this here...
Lets take an example of an online-course where instructor of the course can 
make changes to the order number of the course-contents.. suppose dnd 
functionality has been provided to him. When he shuffles the 
course-contents, a new order number is assigned to each content accordingly 
and persisted in database through a field setup for it in the model. In 
this case also, there will be no changes in the source-code rather changes 
will be saved in database and loaded when page is refreshed.

On Monday, September 14, 2020 at 12:36:01 PM UTC-4 Elliot wrote:

> I am familiar with the various events in building a dnd.  I am trying to 
> find out what is supposed to happen to the HTML source when a drag and drop 
> works. Can anyone explain this to me.? After an apparently successful drag 
> and drop I see no changes to the underlying HTML. I have been using Django 
> 3.0.10 and Python 3.8.1 and javascript. 
>
> If I do a "view source" after a dnd should the source code now reflect the 
> changes made by the dnd?  Exactly what is supposed to happen?  I am not 
> submitting any code because I just want to find out how it is supposed to 
> work.
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b776f2b9-2e4b-4ef0-bfa2-9fe24ddb5f51n%40googlegroups.com.


Re: HTML5 drag and drop: How does it really work?

2020-09-14 Thread coolguy
The changes are done through script which you are doing at this time... the 
changes would only be visual for user and would not impact the source code.

following may be irrelevant for you but i would added this here...
Lets take an example of an online-course where instructor of the course can 
make changes to the order number of the course-contents.. suppose dnd 
functionality has been provided to him. When he shuffles the 
course-contents, a new order number is assigned to each content accordingly 
and persisted in database through a field setup for it in the model. In 
this case also, there will be no changes in the source-code rather changes 
will be saved in database and loaded when page is refreshed.

On Monday, September 14, 2020 at 12:36:01 PM UTC-4 Elliot wrote:

> I am familiar with the various events in building a dnd.  I am trying to 
> find out what is supposed to happen to the HTML source when a drag and drop 
> works. Can anyone explain this to me.? After an apparently successful drag 
> and drop I see no changes to the underlying HTML. I have been using Django 
> 3.0.10 and Python 3.8.1 and javascript. 
>
> If I do a "view source" after a dnd should the source code now reflect the 
> changes made by the dnd?  Exactly what is supposed to happen?  I am not 
> submitting any code because I just want to find out how it is supposed to 
> work.
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ee507e6d-5a0b-4e01-8142-ca6a9baae830n%40googlegroups.com.


Re: Change DateField Like this

2020-09-14 Thread coolguy
please explain in detail where do you want this change views? 

On Monday, September 14, 2020 at 3:56:37 PM UTC-4 kkwaq...@gmail.com wrote:

> How to change date format in django (mmdd to ddmm)
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d2aa631e-7f10-476d-bb01-c844c673877en%40googlegroups.com.


Re: Help me with the view please

2020-09-14 Thread coolguy
not sure what are you looking for... but based on your model setup... 
school fees is setup once so we picked it up from first object/record from 
table, while paid fees are collected quarterly or whatever means there will 
be more than one transaction in fee table. We have already calculated the 
"paid_fees" from fee table like this
>>>  
  paid_fees = student.fee_set.aggregate(total_paid_fees=Sum('paid_fees'))

I definitely want to help as long as i know what you are looking for :)


On Monday, September 14, 2020 at 4:26:48 PM UTC-4 dex9...@gmail.com wrote:

> Thanks it has worked, but it doesn’t work with my total_paid_fees, I want 
> to be automatically checked when school_fees substracts summation of all 
> paid_fees, just like this solution you provided me with the last time
>
> first_record = student.fee_set.first()
>
>  school_fees = first_record.school_fees
>
>   paid_fees = student.fee_set.aggregate(total_paid_fees=Sum('paid_fees'))
>
>balance_fees =  school_fees - paid_fees["total_paid_fees"] 
>
>  
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Monday, September 14, 2020 9:09 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> Its simple... in your fee models' save method check that 
> self.remaining_fees is zero then make self.completed field to true... I 
> added else clause in case if admin make changes to paid fees and after 
> changes student still has some dues.
>
>  
>
> def save(self, *args, **kwargs):
>
>  
>
> self.remaining_fees = self.school_fees - self.paid_fees
>
> if self.remaining_fees == 0:
>
> self.completed = True
>
> else:
>
> self.completed = False
>
> 
>
> super().save(*args, **kwargs)
>
>  
>
> On Monday, September 14, 2020 at 7:11:51 AM UTC-4 dex9...@gmail.com wrote:
>
> Thank you brother @coolguy, I have put to work your latest solution and it 
> has worked like a charm.I have been learning a lot from you lately, as you 
> know i am still a beginner, i would love to learn one more thing from 
> you..i have a boolean field "completed", and i want django to automatically 
> check it when balance_fees or remaining_fees is equal to zero, 
>
> Here is  my model
>
>  my template
>
>  
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Friday, September 11, 2020 8:51 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> Technically your Fee model is designed incorrectly. You should have 
> separate models for 'fees' and 'fees_paid' where fee would have been the 
> foreign key in 'fees_paid. Fee should have a property like annual fee etc 
> for each student as fee may be different based on student discounts etc. 
> Then when student pays the fees, fees should go in a separate transactional 
> table i.e. 'fees paid'. In your scenario, does each row in fee table 
> carries the annual/school fee? if so then yes summing them up will 
> definitely cause incorrect figure.
>
>  
>
> Here is what i would do if i don't change my models structure.
>
>  
>
> views.py
>
> ===
>
> def student_detail(request, pk):
>
> student = Student.objects.get(id=pk)
>
> 
>
> *# in your case pick the first record from fee_set*
>
> first_record = student.fee_set.first()
>
> school_fees = first_record.school_fees
>
> 
>
> paid_fees = student.fee_set.aggregate(total_paid_fees=Sum('paid_fees'))
>
> 
>
> balance_fees =  school_fees - paid_fees["total_paid_fees"] 
>
>  
>
> context = {"student": student,
>
>"paid_fees": paid_fees,
>
>"school_fees": school_fees,
>
>"balance_fees": balance_fees, }
>
>  
>
> return render(request, "student_details.html", context)
>
>  
>
> template
>
> ===
>
> 
>
> Student Detail
>
> Student name: {{ student.name }}
>
> School fees: {{ school_fees }}
>
> Paid fees: {{ paid_fees.total_paid_fees }}
>
> Remaining fees: {{ balance_fees }}
>
> 
>
>  
>
> Output:
>
> 
>
> Student name: student1
>
> School fees: 10.0
>
> Paid fees: 35000.0
>
> Remaining fees: 65000.0
>
>  
>
> On Friday, September 11, 2020 at 5:25:28 AM UTC-4 dex9...@gmail.com

Re: I am getting this error while I click on comment button which i mention in line 51 in html file.

2020-09-14 Thread coolguy
This is not the same error...

What is this 'Post' in your >>> post=Post.objects.filter(Post, pk=ID)
based on the django error you are using model here which is not how filter 
works...

this should be a field name like xxx.filter(field_name__id=ID)

I would suggest you to refer to documentation on filter to familiarize 
yourself.

https://docs.djangoproject.com/en/3.1/topics/db/aggregation/

https://docs.djangoproject.com/en/3.1/topics/db/aggregation/#filter-and-exclude




On Monday, September 14, 2020 at 3:09:04 PM UTC-4 yashlan...@gmail.com 
wrote:

> still i am getting error.[image: 8.PNG][image: 10.PNG][image: 13.PNG][image: 
> 12.PNG]
>
> On Saturday, September 12, 2020 at 9:59:16 PM UTC+5:30 coolguy wrote:
>
>> Can't see the line number in your provided screens.
>> However, i can see you have additional id id={{ i.id }}added to your 
>> button line. (remove it)
>> You have already provided the id in href="{% url 'userpage:post_detail' 
>> i.id %}" attribute.
>>
>> On Saturday, September 12, 2020 at 4:34:10 AM UTC-4 yashlan...@gmail.com 
>> wrote:
>>
>>> [image: 1..PNG]
>>> [image: 2.PNG]
>>> [image: 3.PNG]
>>> [image: 4.PNG]
>>>
>>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d6eb7545-8312-419a-ac5a-07edaaee6fb8n%40googlegroups.com.


Re: Help me with the view please

2020-09-14 Thread coolguy
Its simple... in your fee models' save method check that 
self.remaining_fees is zero then make self.completed field to true... I 
added else clause in case if admin make changes to paid fees and after 
changes student still has some dues.

def save(self, *args, **kwargs):
self.remaining_fees = self.school_fees - self.paid_fees
if self.remaining_fees == 0:
self.completed = True
else:
self.completed = False

super().save(*args, **kwargs)

On Monday, September 14, 2020 at 7:11:51 AM UTC-4 dex9...@gmail.com wrote:

> Thank you brother @coolguy, I have put to work your latest solution and 
> it has worked like a charm.I have been learning a lot from you lately, as 
> you know i am still a beginner, i would love to learn one more thing from 
> you..i have a boolean field "completed", and i want django to automatically 
> check it when balance_fees or remaining_fees is equal to zero, 
>
> Here is  my model
> [image: image.png]
>
>  my template
> [image: image.png]
>
>  
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Friday, September 11, 2020 8:51 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> Technically your Fee model is designed incorrectly. You should have 
> separate models for 'fees' and 'fees_paid' where fee would have been the 
> foreign key in 'fees_paid. Fee should have a property like annual fee etc 
> for each student as fee may be different based on student discounts etc. 
> Then when student pays the fees, fees should go in a separate transactional 
> table i.e. 'fees paid'. In your scenario, does each row in fee table 
> carries the annual/school fee? if so then yes summing them up will 
> definitely cause incorrect figure.
>
>  
>
> Here is what i would do if i don't change my models structure.
>
>  
>
> views.py
>
> ===
>
> def student_detail(request, pk):
>
> student = Student.objects.get(id=pk)
>
> 
>
> *# in your case pick the first record from fee_set*
>
> first_record = student.fee_set.first()
>
> school_fees = first_record.school_fees
>
> 
>
> paid_fees = student.fee_set.aggregate(total_paid_fees=Sum('paid_fees'))
>
> 
>
> balance_fees =  school_fees - paid_fees["total_paid_fees"] 
>
>  
>
> context = {"student": student,
>
>"paid_fees": paid_fees,
>
>"school_fees": school_fees,
>
>"balance_fees": balance_fees, }
>
>  
>
> return render(request, "student_details.html", context)
>
>  
>
> template
>
> ===
>
> 
>
> Student Detail
>
> Student name: {{ student.name }}
>
> School fees: {{ school_fees }}
>
> Paid fees: {{ paid_fees.total_paid_fees }}
>
> Remaining fees: {{ balance_fees }}
>
> 
>
>  
>
> Output:
>
> 
>
> Student name: student1
>
> School fees: 10.0
>
> Paid fees: 35000.0
>
> Remaining fees: 65000.0
>
>  
>
> On Friday, September 11, 2020 at 5:25:28 AM UTC-4 dex9...@gmail.com wrote:
>
> Sorry for bothering you @coolguy, you’re the only person who seems to be 
> nice to a Django beginner developer like me, and I would like to bother you 
> one more time
>
> Your solution for using methods in models is perfectly fine
>
> You see I want school_fees to be a fixed amount, example $300
>
> So when a student pays more than once(student.fee_set), lets say this 
> month student 1 pays $50 
>
> And another month pays $100 dollars, I want payments to added and 
> subtracted from fixed schools_fees($300)
>
> Remainingfees to be $300 – (($50)+($100))
>
>  
>
> BUT what “ 
> fees = student.fee_set.aggregate(total_paid_fees=Sum('paid_fees'), 
> total_school_fees=Sum('school_fees'))” 
> does is that it sums both paid fees school fees every time a student pays, 
> I want only paid fees to added every time a student pays but not school fees
>
>  
>
>  
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Friday, September 11, 2020 4:27 AM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> If i choose to go with your way of calculation, i would do this...
>
>  
>
> def student_detail(request, pk):
>
> student = Student.objects.get(id=pk)
>
>
> fees = student.fee_set.aggregate(total_paid

Re: AttributeError: object has no attribute 'user' while trying to access instance.user.id

2020-09-14 Thread coolguy
If i had to stick to your code then i would save the file with 
instance.username. username is available and folder would be readable as 
well.

However, as i mentioned in my last reply and seems you agreed, 
save/register the employee and then have employee upload the picture.

On Monday, September 14, 2020 at 8:20:21 AM UTC-4 mislav@gmail.com 
wrote:

> What I can do is first register the employee via a register form, then 
> once he logs in ask him/her for the profile picture. *Can I do that this 
> way? *
>
> If I do it this way, I don't have to change my model in any way.
>
> Dana nedjelja, 13. rujna 2020. u 18:11:18 UTC+2 korisnik coolguy napisao 
> je:
>
>> not sure about the purpose of showing that example in Django 
>> documentation while its comments are clear that "object will not have been 
>> saved to the database yet, so if it uses the default AutoField, *it 
>> might not yet have a value for its primary key field*."
>>
>> so that's the reason for having None with file path.
>>
>> In this approach what i can see is to save the employee first without 
>> file and then edit and select the file.
>>
>> I would not use this approach and rather keep it simple as followed:
>>
>> photo = models.ImageField(upload_to='employee/%Y/%m/%d/', blank=True)
>>
>> On Sunday, September 13, 2020 at 5:41:18 AM UTC-4 mislav@gmail.com 
>> wrote:
>>
>>> Hey coolguy,
>>>
>>> thanks for responding. After I changed that line as you suggested that 
>>> error is solved, *but when I add the user through the admin interface, 
>>> I get None as the ID* (the folder that gets created in the 
>>> */media/users* is titled *None*). I'm not sure if this is expected 
>>> behavior.
>>>
>>> I haven't added the registration or the login yet, so maybe the ID gets 
>>> a value when someone is actually registering.
>>>
>>> Let me know.
>>>
>>> Best,
>>> Mislav
>>>
>>> Dana subota, 12. rujna 2020. u 21:57:21 UTC+2 korisnik coolguy napisao 
>>> je:
>>>
>>>> I wanted to see your model to understand but i realized after my last 
>>>> post that you are using "instance.user.id" while your employee 
>>>> instance does not have user field. (had to go somewhere urgently) >>> 
>>>> return "employees/media/users/{0}/profile_picture.{1}".format(
>>>> instance.user.id, extension)  
>>>>
>>>> change it as follow and remove user from it.
>>>> return "employees/media/users/{0}/profile_picture.{1}".format(
>>>> instance.id <http://instance.user.id/>, extension)  
>>>>
>>>> It should work...
>>>>
>>>> On Saturday, September 12, 2020 at 3:17:28 PM UTC-4 
>>>> mislav@gmail.com wrote:
>>>>
>>>>> coolguy here is the complete Employee model:
>>>>>
>>>>> class Employee(models.Model): #TODO: Double-check this
>>>>> username = models.CharField(max_length=50, unique=True)
>>>>> email = models.EmailField()
>>>>> password = models.CharField(max_length=50)
>>>>> first_name = models.CharField(max_length=150)
>>>>> last_name = models.CharField(max_length=100)
>>>>> website = models.URLField(max_length=200, blank=True)
>>>>>
>>>>> profile_picture = models.ImageField(upload_to=get_upload_path, 
>>>>> blank=True, null=True)
>>>>> 
>>>>> def __str__(self):
>>>>> return str(self.first_name) + str(self.last_name)
>>>>>
>>>>> *Why do I need the foreign key to User in the first place?* I don't 
>>>>> recall seing the foreign key to User in any one of the tutorials.
>>>>> Dana subota, 12. rujna 2020. u 20:20:11 UTC+2 korisnik coolguy napisao 
>>>>> je:
>>>>>
>>>>>> Please share the complete employee model. It seems you are missing 
>>>>>> User foreign key in it.
>>>>>>
>>>>>> On Saturday, September 12, 2020 at 2:03:20 PM UTC-4 
>>>>>> mislav@gmail.com wrote:
>>>>>>
>>>>>>> Hey guys,
>>>>>>>
>>>>>>> I have the following code in models.py file in one of my apps:
>>>>>>>
>>>>>>> def get_upload_path(instance, filename):
>>>>>>> extension = filename.spl

Re: Help me with the view please

2020-09-14 Thread coolguy
Its simple... in your fee models' save method check that 
self.remaining_fees is zero then make self.completed field to true..

def save(self, *args, **kwargs):
self.remaining_fees = self.school_fees - self.paid_fees
if self.remaining_fees == 0:
self.completed = True
super().save(*args, **kwargs)

On Monday, September 14, 2020 at 7:11:51 AM UTC-4 dex9...@gmail.com wrote:

> Thank you brother @coolguy, I have put to work your latest solution and 
> it has worked like a charm.I have been learning a lot from you lately, as 
> you know i am still a beginner, i would love to learn one more thing from 
> you..i have a boolean field "completed", and i want django to automatically 
> check it when balance_fees or remaining_fees is equal to zero, 
>
> Here is  my model
> [image: image.png]
>
>  my template
> [image: image.png]
>
>  
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Friday, September 11, 2020 8:51 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> Technically your Fee model is designed incorrectly. You should have 
> separate models for 'fees' and 'fees_paid' where fee would have been the 
> foreign key in 'fees_paid. Fee should have a property like annual fee etc 
> for each student as fee may be different based on student discounts etc. 
> Then when student pays the fees, fees should go in a separate transactional 
> table i.e. 'fees paid'. In your scenario, does each row in fee table 
> carries the annual/school fee? if so then yes summing them up will 
> definitely cause incorrect figure.
>
>  
>
> Here is what i would do if i don't change my models structure.
>
>  
>
> views.py
>
> ===
>
> def student_detail(request, pk):
>
> student = Student.objects.get(id=pk)
>
> 
>
> *# in your case pick the first record from fee_set*
>
> first_record = student.fee_set.first()
>
> school_fees = first_record.school_fees
>
> 
>
> paid_fees = student.fee_set.aggregate(total_paid_fees=Sum('paid_fees'))
>
> 
>
> balance_fees =  school_fees - paid_fees["total_paid_fees"] 
>
>  
>
> context = {"student": student,
>
>"paid_fees": paid_fees,
>
>"school_fees": school_fees,
>
>"balance_fees": balance_fees, }
>
>  
>
> return render(request, "student_details.html", context)
>
>  
>
> template
>
> ===
>
> 
>
> Student Detail
>
> Student name: {{ student.name }}
>
> School fees: {{ school_fees }}
>
> Paid fees: {{ paid_fees.total_paid_fees }}
>
> Remaining fees: {{ balance_fees }}
>
> 
>
>  
>
> Output:
>
> 
>
> Student name: student1
>
> School fees: 10.0
>
> Paid fees: 35000.0
>
> Remaining fees: 65000.0
>
>  
>
> On Friday, September 11, 2020 at 5:25:28 AM UTC-4 dex9...@gmail.com wrote:
>
> Sorry for bothering you @coolguy, you’re the only person who seems to be 
> nice to a Django beginner developer like me, and I would like to bother you 
> one more time
>
> Your solution for using methods in models is perfectly fine
>
> You see I want school_fees to be a fixed amount, example $300
>
> So when a student pays more than once(student.fee_set), lets say this 
> month student 1 pays $50 
>
> And another month pays $100 dollars, I want payments to added and 
> subtracted from fixed schools_fees($300)
>
> Remainingfees to be $300 – (($50)+($100))
>
>  
>
> BUT what “ 
> fees = student.fee_set.aggregate(total_paid_fees=Sum('paid_fees'), 
> total_school_fees=Sum('school_fees'))” 
> does is that it sums both paid fees school fees every time a student pays, 
> I want only paid fees to added every time a student pays but not school fees
>
>  
>
>  
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Friday, September 11, 2020 4:27 AM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> If i choose to go with your way of calculation, i would do this...
>
>  
>
> def student_detail(request, pk):
>
> student = Student.objects.get(id=pk)
>
>
> fees = student.fee_set.aggregate(total_paid_fees=Sum('paid_fees'), 
> total_school_fees=Sum('school_fees'))
>
>  
>
> balance_fees = fees["total_school_fees"] - fees["total_paid_fees&qu

Re: AttributeError: object has no attribute 'user' while trying to access instance.user.id

2020-09-13 Thread coolguy
not sure about the purpose of showing that example in Django documentation 
while its comments are clear that "object will not have been saved to the 
database yet, so if it uses the default AutoField, *it might not yet have a 
value for its primary key field*."

so that's the reason for having None with file path.

In this approach what i can see is to save the employee first without file 
and then edit and select the file.

I would not use this approach and rather keep it simple as followed:

photo = models.ImageField(upload_to='employee/%Y/%m/%d/', blank=True)

On Sunday, September 13, 2020 at 5:41:18 AM UTC-4 mislav@gmail.com 
wrote:

> Hey coolguy,
>
> thanks for responding. After I changed that line as you suggested that 
> error is solved, *but when I add the user through the admin interface, I 
> get None as the ID* (the folder that gets created in the */media/users* 
> is titled *None*). I'm not sure if this is expected behavior.
>
> I haven't added the registration or the login yet, so maybe the ID gets a 
> value when someone is actually registering.
>
> Let me know.
>
> Best,
> Mislav
>
> Dana subota, 12. rujna 2020. u 21:57:21 UTC+2 korisnik coolguy napisao je:
>
>> I wanted to see your model to understand but i realized after my last 
>> post that you are using "instance.user.id" while your employee instance 
>> does not have user field. (had to go somewhere urgently) >>> return 
>> "employees/media/users/{0}/profile_picture.{1}".format(instance.user.id, 
>> extension)  
>>
>> change it as follow and remove user from it.
>> return "employees/media/users/{0}/profile_picture.{1}".format(instance.id 
>> <http://instance.user.id/>, extension)  
>>
>> It should work...
>>
>> On Saturday, September 12, 2020 at 3:17:28 PM UTC-4 mislav@gmail.com 
>> wrote:
>>
>>> coolguy here is the complete Employee model:
>>>
>>> class Employee(models.Model): #TODO: Double-check this
>>> username = models.CharField(max_length=50, unique=True)
>>> email = models.EmailField()
>>> password = models.CharField(max_length=50)
>>> first_name = models.CharField(max_length=150)
>>> last_name = models.CharField(max_length=100)
>>> website = models.URLField(max_length=200, blank=True)
>>>
>>> profile_picture = models.ImageField(upload_to=get_upload_path, 
>>> blank=True, null=True)
>>> 
>>> def __str__(self):
>>> return str(self.first_name) + str(self.last_name)
>>>
>>> *Why do I need the foreign key to User in the first place?* I don't 
>>> recall seing the foreign key to User in any one of the tutorials.
>>> Dana subota, 12. rujna 2020. u 20:20:11 UTC+2 korisnik coolguy napisao 
>>> je:
>>>
>>>> Please share the complete employee model. It seems you are missing User 
>>>> foreign key in it.
>>>>
>>>> On Saturday, September 12, 2020 at 2:03:20 PM UTC-4 
>>>> mislav@gmail.com wrote:
>>>>
>>>>> Hey guys,
>>>>>
>>>>> I have the following code in models.py file in one of my apps:
>>>>>
>>>>> def get_upload_path(instance, filename):
>>>>> extension = filename.split('.')[-1]
>>>>> return "employees/media/users/{0}/profile_picture.{1}".format(
>>>>> instance.user.id, extension)
>>>>>
>>>>> class Employee(models.Model):
>>>>> # some attributes here
>>>>> profile_picture = models.ImageField(upload_to=get_upload_path, 
>>>>> blank=True, null=True)
>>>>>
>>>>> I am getting the following error when I try to add an Employee via the 
>>>>> admin interface:
>>>>>
>>>>> AttributeError at /admin/employees/employee/add/
>>>>>
>>>>> 'Employee' object has no attribute 'user'
>>>>>
>>>>> *I don't know where this error is stemming from.* I took the 
>>>>> get_upload_path function from the official Django FIleField 
>>>>> documentation 
>>>>> <https://docs.djangoproject.com/en/3.1/ref/models/fields/#filefield>.
>>>>>
>>>>> Any ideas as to what is going on here?
>>>>>
>>>>> Best,
>>>>> Mislav
>>>>>
>>>>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7daceb0e-c1d5-4b9a-b64b-7dbabec6118fn%40googlegroups.com.


Re: AttributeError: object has no attribute 'user' while trying to access instance.user.id

2020-09-13 Thread coolguy
May the purpose of showing that example in Django documentation is 
something else. If you read the comments there , there is a potential issue 
that the instance that they suggest to use mostly would have not been 
persisted in the database if AutoField has been used. so there will be 'no' 
id as yet resulting None is being saved with file path.

In this approach what i can see is to save the employee first without file 
and then edit and select the file.

I would not use this approach and rather keep it simple as followed:

photo = models.ImageField(upload_to='employee/%Y/%m/%d/', blank=True)

On Sunday, September 13, 2020 at 5:41:18 AM UTC-4 mislav@gmail.com 
wrote:

> Hey coolguy,
>
> thanks for responding. After I changed that line as you suggested that 
> error is solved, *but when I add the user through the admin interface, I 
> get None as the ID* (the folder that gets created in the */media/users* 
> is titled *None*). I'm not sure if this is expected behavior.
>
> I haven't added the registration or the login yet, so maybe the ID gets a 
> value when someone is actually registering.
>
> Let me know.
>
> Best,
> Mislav
>
> Dana subota, 12. rujna 2020. u 21:57:21 UTC+2 korisnik coolguy napisao je:
>
>> I wanted to see your model to understand but i realized after my last 
>> post that you are using "instance.user.id" while your employee instance 
>> does not have user field. (had to go somewhere urgently) >>> return 
>> "employees/media/users/{0}/profile_picture.{1}".format(instance.user.id, 
>> extension)  
>>
>> change it as follow and remove user from it.
>> return "employees/media/users/{0}/profile_picture.{1}".format(instance.id 
>> <http://instance.user.id/>, extension)  
>>
>> It should work...
>>
>> On Saturday, September 12, 2020 at 3:17:28 PM UTC-4 mislav@gmail.com 
>> wrote:
>>
>>> coolguy here is the complete Employee model:
>>>
>>> class Employee(models.Model): #TODO: Double-check this
>>> username = models.CharField(max_length=50, unique=True)
>>> email = models.EmailField()
>>> password = models.CharField(max_length=50)
>>> first_name = models.CharField(max_length=150)
>>> last_name = models.CharField(max_length=100)
>>> website = models.URLField(max_length=200, blank=True)
>>>
>>> profile_picture = models.ImageField(upload_to=get_upload_path, 
>>> blank=True, null=True)
>>> 
>>> def __str__(self):
>>> return str(self.first_name) + str(self.last_name)
>>>
>>> *Why do I need the foreign key to User in the first place?* I don't 
>>> recall seing the foreign key to User in any one of the tutorials.
>>> Dana subota, 12. rujna 2020. u 20:20:11 UTC+2 korisnik coolguy napisao 
>>> je:
>>>
>>>> Please share the complete employee model. It seems you are missing User 
>>>> foreign key in it.
>>>>
>>>> On Saturday, September 12, 2020 at 2:03:20 PM UTC-4 
>>>> mislav@gmail.com wrote:
>>>>
>>>>> Hey guys,
>>>>>
>>>>> I have the following code in models.py file in one of my apps:
>>>>>
>>>>> def get_upload_path(instance, filename):
>>>>> extension = filename.split('.')[-1]
>>>>> return "employees/media/users/{0}/profile_picture.{1}".format(
>>>>> instance.user.id, extension)
>>>>>
>>>>> class Employee(models.Model):
>>>>> # some attributes here
>>>>> profile_picture = models.ImageField(upload_to=get_upload_path, 
>>>>> blank=True, null=True)
>>>>>
>>>>> I am getting the following error when I try to add an Employee via the 
>>>>> admin interface:
>>>>>
>>>>> AttributeError at /admin/employees/employee/add/
>>>>>
>>>>> 'Employee' object has no attribute 'user'
>>>>>
>>>>> *I don't know where this error is stemming from.* I took the 
>>>>> get_upload_path function from the official Django FIleField 
>>>>> documentation 
>>>>> <https://docs.djangoproject.com/en/3.1/ref/models/fields/#filefield>.
>>>>>
>>>>> Any ideas as to what is going on here?
>>>>>
>>>>> Best,
>>>>> Mislav
>>>>>
>>>>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e8aa1e36-8364-4d0a-b325-f79974763c02n%40googlegroups.com.


Re: AttributeError: object has no attribute 'user' while trying to access instance.user.id

2020-09-12 Thread coolguy
I wanted to see your model to understand but i realized after my last post 
that you are using "instance.user.id" while your employee instance does not 
have user field. (had to go somewhere urgently) >>> return 
"employees/media/users/{0}/profile_picture.{1}".format(instance.user.id, 
extension)  

change it as follow and remove user from it.
return "employees/media/users/{0}/profile_picture.{1}".format(instance.id 
<http://instance.user.id/>, extension)  

It should work...

On Saturday, September 12, 2020 at 3:17:28 PM UTC-4 mislav@gmail.com 
wrote:

> coolguy here is the complete Employee model:
>
> class Employee(models.Model): #TODO: Double-check this
> username = models.CharField(max_length=50, unique=True)
> email = models.EmailField()
> password = models.CharField(max_length=50)
> first_name = models.CharField(max_length=150)
> last_name = models.CharField(max_length=100)
> website = models.URLField(max_length=200, blank=True)
>
> profile_picture = models.ImageField(upload_to=get_upload_path, 
> blank=True, null=True)
> 
> def __str__(self):
> return str(self.first_name) + str(self.last_name)
>
> *Why do I need the foreign key to User in the first place?* I don't 
> recall seing the foreign key to User in any one of the tutorials.
> Dana subota, 12. rujna 2020. u 20:20:11 UTC+2 korisnik coolguy napisao je:
>
>> Please share the complete employee model. It seems you are missing User 
>> foreign key in it.
>>
>> On Saturday, September 12, 2020 at 2:03:20 PM UTC-4 mislav@gmail.com 
>> wrote:
>>
>>> Hey guys,
>>>
>>> I have the following code in models.py file in one of my apps:
>>>
>>> def get_upload_path(instance, filename):
>>> extension = filename.split('.')[-1]
>>> return "employees/media/users/{0}/profile_picture.{1}".format(
>>> instance.user.id, extension)
>>>
>>> class Employee(models.Model):
>>> # some attributes here
>>> profile_picture = models.ImageField(upload_to=get_upload_path, 
>>> blank=True, null=True)
>>>
>>> I am getting the following error when I try to add an Employee via the 
>>> admin interface:
>>>
>>> AttributeError at /admin/employees/employee/add/
>>>
>>> 'Employee' object has no attribute 'user'
>>>
>>> *I don't know where this error is stemming from.* I took the 
>>> get_upload_path function from the official Django FIleField 
>>> documentation 
>>> <https://docs.djangoproject.com/en/3.1/ref/models/fields/#filefield>.
>>>
>>> Any ideas as to what is going on here?
>>>
>>> Best,
>>> Mislav
>>>
>>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8f08f03a-9617-48b9-bfdb-d00e44652cf1n%40googlegroups.com.


Re: help me it shows error.

2020-09-12 Thread coolguy
change post:pk to i.id

also fix line and delete id={{ i.id }}

On Saturday, September 12, 2020 at 2:54:16 PM UTC-4 yashlan...@gmail.com 
wrote:

> [image: 5.PNG]
> [image: 8.PNG]
> [image: 9.PNG]
> [image: 10.PNG]
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0770bafa-3f96-4b64-9f09-3f0418007c6en%40googlegroups.com.


Re: I am getting an error message about a non-nullable field in existing rows, even though I dropped all rows via the admin interface

2020-09-12 Thread coolguy
Keep this handy as well... 

https://docs.djangoproject.com/en/3.1/ref/migration-operations/#addfield

On Saturday, September 12, 2020 at 1:43:37 PM UTC-4 mislav@gmail.com 
wrote:

> A question to coolguy:
>
> *What should I have done if I selected option 1?* I get the Python shell 
> and if I input a default value - let's say "te...@test.com", what else do 
> I need to do? I tried to just provide the default value, but it wouldn't 
> accept it, complaining that it was invalid Python (as it is). *Do I need 
> to select the existing rows from the database and set them all to have the 
> value of the new field to the default value? If yes, how do I do this most 
> efficiently (in code)?*
>
> Best,
> Mislav
>
> Dana subota, 12. rujna 2020. u 18:21:14 UTC+2 korisnik coolguy napisao je:
>
>> just FYI...
>>
>> You didn't have to delete the db.sqllite3 file rather would have followed 
>> on-screen direction and provided a default value to persist in the existing 
>> records in your database. Later you could have edited the info through your 
>> program and make correction.
>>
>> This is pretty normal situation where we added new fields/properties in 
>> our model while database has existing records. You wouldn't be able to 
>> delete the database in case you are using relational database like postgres 
>> or mysql.
>>
>> Thanks
>>
>> On Saturday, September 12, 2020 at 10:44:11 AM UTC-4 mislav@gmail.com 
>> wrote:
>>
>>> Hey Danish,
>>>
>>> I was able to resolve the error by deleting the *db.sqlite3* file from 
>>> my project root directory and all of the *migrations* folders from all 
>>> of my apps.
>>>
>>> Thank you for responding.
>>>
>>> Best,
>>> Mislav
>>>
>>>
>>> Dana subota, 12. rujna 2020. u 14:56:13 UTC+2 korisnik 
>>> mailto...@gmail.com napisao je:
>>>
>>>> you need to give default value in email. seems few records are already 
>>>> exist.
>>>>
>>>> else delete sqllite file and try again.
>>>>
>>>> On Sat, Sep 12, 2020 at 6:22 PM Mislav Jurić  
>>>> wrote:
>>>>
>>>>> Hey guys,
>>>>>
>>>>> I added an EmailField 
>>>>> <https://docs.djangoproject.com/en/3.1/ref/models/fields/#emailfield> 
>>>>> to some of my already existing models. When I tried to run:
>>>>>
>>>>> *python manage.py makemigrations*
>>>>>
>>>>> I got the following prompt:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> *You are trying to add a non-nullable field 'email' to employee 
>>>>> without a default; we can't do that (the database needs something to 
>>>>> populate existing rows).Please select a fix: 1) Provide a one-off default 
>>>>> now (will be set on all existing rows with a null value for this column) 
>>>>> 2) 
>>>>> Quit, and let me add a default in models.pySelect an option: *
>>>>>
>>>>> I quit the prompt (option two). Then I went ahead and commented out 
>>>>> the new EmailField in the models I added them and I dropped all of the 
>>>>> database rows in my entire database (not just the rows related to the 
>>>>> models where I added the new email field; I dropped every row from every 
>>>>> table).
>>>>>
>>>>> Then I uncommented the new EmailField and tried to run:
>>>>>
>>>>> *python manage.py makemigrations*
>>>>>
>>>>> again, *but I still get the prompt above*! I selected option 1 a few 
>>>>> times, but I'm not sure what I need to do. I tried to supply a value for 
>>>>> that field, but the prompt is a Python shell, so I'm not sure what I need 
>>>>> to do if I select option 1.
>>>>>
>>>>> *How do I fix this?*
>>>>>
>>>>> Best,
>>>>> Mislav
>>>>>
>>>>>
>>>>> -- 
>>>>> 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 view this discussion on the web visit 
>>>>> https://groups.google.com/d/msgid/django-users/CABTqP_HKzXHOAKC-y0AedjsxtBcgKLEk9Cj9J7nhgoD1EpNf%2BA%40mail.gmail.com
>>>>>  
>>>>> <https://groups.google.com/d/msgid/django-users/CABTqP_HKzXHOAKC-y0AedjsxtBcgKLEk9Cj9J7nhgoD1EpNf%2BA%40mail.gmail.com?utm_medium=email_source=footer>
>>>>> .
>>>>>
>>>>
>>>>
>>>> -- 
>>>> Thanks & Regards 
>>>>   
>>>> Regards, 
>>>> Danish
>>>>
>>>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/eb23d859-0d78-4115-a461-cf8bd547493dn%40googlegroups.com.


Re: I am getting an error message about a non-nullable field in existing rows, even though I dropped all rows via the admin interface

2020-09-12 Thread coolguy
Interesting... did you try the email with quotes or without it

On Saturday, September 12, 2020 at 1:43:37 PM UTC-4 mislav@gmail.com 
wrote:

> A question to coolguy:
>
> *What should I have done if I selected option 1?* I get the Python shell 
> and if I input a default value - let's say "te...@test.com", what else do 
> I need to do? I tried to just provide the default value, but it wouldn't 
> accept it, complaining that it was invalid Python (as it is). *Do I need 
> to select the existing rows from the database and set them all to have the 
> value of the new field to the default value? If yes, how do I do this most 
> efficiently (in code)?*
>
> Best,
> Mislav
>
> Dana subota, 12. rujna 2020. u 18:21:14 UTC+2 korisnik coolguy napisao je:
>
>> just FYI...
>>
>> You didn't have to delete the db.sqllite3 file rather would have followed 
>> on-screen direction and provided a default value to persist in the existing 
>> records in your database. Later you could have edited the info through your 
>> program and make correction.
>>
>> This is pretty normal situation where we added new fields/properties in 
>> our model while database has existing records. You wouldn't be able to 
>> delete the database in case you are using relational database like postgres 
>> or mysql.
>>
>> Thanks
>>
>> On Saturday, September 12, 2020 at 10:44:11 AM UTC-4 mislav@gmail.com 
>> wrote:
>>
>>> Hey Danish,
>>>
>>> I was able to resolve the error by deleting the *db.sqlite3* file from 
>>> my project root directory and all of the *migrations* folders from all 
>>> of my apps.
>>>
>>> Thank you for responding.
>>>
>>> Best,
>>> Mislav
>>>
>>>
>>> Dana subota, 12. rujna 2020. u 14:56:13 UTC+2 korisnik 
>>> mailto...@gmail.com napisao je:
>>>
>>>> you need to give default value in email. seems few records are already 
>>>> exist.
>>>>
>>>> else delete sqllite file and try again.
>>>>
>>>> On Sat, Sep 12, 2020 at 6:22 PM Mislav Jurić  
>>>> wrote:
>>>>
>>>>> Hey guys,
>>>>>
>>>>> I added an EmailField 
>>>>> <https://docs.djangoproject.com/en/3.1/ref/models/fields/#emailfield> 
>>>>> to some of my already existing models. When I tried to run:
>>>>>
>>>>> *python manage.py makemigrations*
>>>>>
>>>>> I got the following prompt:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> *You are trying to add a non-nullable field 'email' to employee 
>>>>> without a default; we can't do that (the database needs something to 
>>>>> populate existing rows).Please select a fix: 1) Provide a one-off default 
>>>>> now (will be set on all existing rows with a null value for this column) 
>>>>> 2) 
>>>>> Quit, and let me add a default in models.pySelect an option: *
>>>>>
>>>>> I quit the prompt (option two). Then I went ahead and commented out 
>>>>> the new EmailField in the models I added them and I dropped all of the 
>>>>> database rows in my entire database (not just the rows related to the 
>>>>> models where I added the new email field; I dropped every row from every 
>>>>> table).
>>>>>
>>>>> Then I uncommented the new EmailField and tried to run:
>>>>>
>>>>> *python manage.py makemigrations*
>>>>>
>>>>> again, *but I still get the prompt above*! I selected option 1 a few 
>>>>> times, but I'm not sure what I need to do. I tried to supply a value for 
>>>>> that field, but the prompt is a Python shell, so I'm not sure what I need 
>>>>> to do if I select option 1.
>>>>>
>>>>> *How do I fix this?*
>>>>>
>>>>> Best,
>>>>> Mislav
>>>>>
>>>>>
>>>>> -- 
>>>>> 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 view this discussion on the web visit 
>>>>> https://groups.google.com/d/msgid/django-users/CABTqP_HKzXHOAKC-y0AedjsxtBcgKLEk9Cj9J7nhgoD1EpNf%2BA%40mail.gmail.com
>>>>>  
>>>>> <https://groups.google.com/d/msgid/django-users/CABTqP_HKzXHOAKC-y0AedjsxtBcgKLEk9Cj9J7nhgoD1EpNf%2BA%40mail.gmail.com?utm_medium=email_source=footer>
>>>>> .
>>>>>
>>>>
>>>>
>>>> -- 
>>>> Thanks & Regards 
>>>>   
>>>> Regards, 
>>>> Danish
>>>>
>>>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8f0c98b3-bea3-4e47-977c-61323df4cf23n%40googlegroups.com.


Re: AttributeError: object has no attribute 'user' while trying to access instance.user.id

2020-09-12 Thread coolguy
Please share the complete employee model. It seems you are missing User 
foreign key in it.

On Saturday, September 12, 2020 at 2:03:20 PM UTC-4 mislav@gmail.com 
wrote:

> Hey guys,
>
> I have the following code in models.py file in one of my apps:
>
> def get_upload_path(instance, filename):
> extension = filename.split('.')[-1]
> return "employees/media/users/{0}/profile_picture.{1}".format(
> instance.user.id, extension)
>
> class Employee(models.Model):
> # some attributes here
> profile_picture = models.ImageField(upload_to=get_upload_path, 
> blank=True, null=True)
>
> I am getting the following error when I try to add an Employee via the 
> admin interface:
>
> AttributeError at /admin/employees/employee/add/
>
> 'Employee' object has no attribute 'user'
>
> *I don't know where this error is stemming from.* I took the 
> get_upload_path function from the official Django FIleField documentation 
> .
>
> Any ideas as to what is going on here?
>
> Best,
> Mislav
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7f3940db-9144-4b68-bd83-095322b51af2n%40googlegroups.com.


Re: Help with payment processing in django

2020-09-12 Thread coolguy
Buddy... did you design your project or you want us to design it for you... 
did you create models, views...

On Friday, September 11, 2020 at 6:52:31 AM UTC-4 shyam.ac...@gmail.com 
wrote:

>
> Hi guys, I am working on a project which offers contents  and every  
> content has a different price. i want the users to see only the overview of 
> the content, and if they want full access to the content they have to buy 
> it. If anyone here has done something like this before please let me know.
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e53f1a1d-fc56-49c7-a5a4-abe19f7d8fdcn%40googlegroups.com.


Re: I am getting this error while I mention all syntax properly.plz help me out.

2020-09-12 Thread coolguy
Please provide the template screen shot since error is generated from 
there... also send separate screen so its viewable.  

On Saturday, September 12, 2020 at 4:35:10 AM UTC-4 yashlan...@gmail.com 
wrote:

> [image: 5.PNG]
> [image: 6.PNG]
> [image: 7.PNG]
> [image: 8.PNG]
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6398f41f-8fd2-4212-9cca-830d3b2107ecn%40googlegroups.com.


Re: I am getting this error while I mention all syntax properly.plz help me out.

2020-09-12 Thread coolguy
Please provide the template screen shot since error is generated from 
there... also send separate screen so i viewable.

On Saturday, September 12, 2020 at 4:35:10 AM UTC-4 yashlan...@gmail.com 
wrote:

> [image: 5.PNG]
> [image: 6.PNG]
> [image: 7.PNG]
> [image: 8.PNG]
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/49719626-a3dd-4683-b984-5acd20b899c8n%40googlegroups.com.


Re: I am getting this error while I click on comment button which i mention in line 51 in html file.

2020-09-12 Thread coolguy
Can't see the line number in your provided screens.
However, i can see you have additional id id={{ i.id }}added to your button 
line. (remove it)
You have already provided the id in href="{% url 'userpage:post_detail' 
i.id %}" attribute.

On Saturday, September 12, 2020 at 4:34:10 AM UTC-4 yashlan...@gmail.com 
wrote:

> [image: 1..PNG]
> [image: 2.PNG]
> [image: 3.PNG]
> [image: 4.PNG]
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/14828234-3ffe-4045-9e96-e4b15be0d6d6n%40googlegroups.com.


Re: I am getting an error message about a non-nullable field in existing rows, even though I dropped all rows via the admin interface

2020-09-12 Thread coolguy
just FYI...

You didn't have to delete the db.sqllite3 file rather would have followed 
on-screen direction and provided a default value to persist in the existing 
records in your database. Later you could have edited the info through your 
program and make correction.

This is pretty normal situation where we added new fields/properties in our 
model while database has existing records. You wouldn't be able to delete 
the database in case you are using relational database like postgres or 
mysql.

Thanks

On Saturday, September 12, 2020 at 10:44:11 AM UTC-4 mislav@gmail.com 
wrote:

> Hey Danish,
>
> I was able to resolve the error by deleting the *db.sqlite3* file from my 
> project root directory and all of the *migrations* folders from all of my 
> apps.
>
> Thank you for responding.
>
> Best,
> Mislav
>
>
> Dana subota, 12. rujna 2020. u 14:56:13 UTC+2 korisnik mailto...@gmail.com 
> napisao je:
>
>> you need to give default value in email. seems few records are already 
>> exist.
>>
>> else delete sqllite file and try again.
>>
>> On Sat, Sep 12, 2020 at 6:22 PM Mislav Jurić  
>> wrote:
>>
>>> Hey guys,
>>>
>>> I added an EmailField 
>>>  
>>> to some of my already existing models. When I tried to run:
>>>
>>> *python manage.py makemigrations*
>>>
>>> I got the following prompt:
>>>
>>>
>>>
>>>
>>>
>>> *You are trying to add a non-nullable field 'email' to employee without 
>>> a default; we can't do that (the database needs something to populate 
>>> existing rows).Please select a fix: 1) Provide a one-off default now (will 
>>> be set on all existing rows with a null value for this column) 2) Quit, and 
>>> let me add a default in models.pySelect an option: *
>>>
>>> I quit the prompt (option two). Then I went ahead and commented out the 
>>> new EmailField in the models I added them and I dropped all of the database 
>>> rows in my entire database (not just the rows related to the models where I 
>>> added the new email field; I dropped every row from every table).
>>>
>>> Then I uncommented the new EmailField and tried to run:
>>>
>>> *python manage.py makemigrations*
>>>
>>> again, *but I still get the prompt above*! I selected option 1 a few 
>>> times, but I'm not sure what I need to do. I tried to supply a value for 
>>> that field, but the prompt is a Python shell, so I'm not sure what I need 
>>> to do if I select option 1.
>>>
>>> *How do I fix this?*
>>>
>>> Best,
>>> Mislav
>>>
>>>
>>> -- 
>>> 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 view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/CABTqP_HKzXHOAKC-y0AedjsxtBcgKLEk9Cj9J7nhgoD1EpNf%2BA%40mail.gmail.com
>>>  
>>> 
>>> .
>>>
>>
>>
>> -- 
>> Thanks & Regards 
>>   
>> Regards, 
>> Danish
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b280d8c4-6a4e-44bd-99d0-58d69e3b25dcn%40googlegroups.com.


Re: Help me with the view please

2020-09-11 Thread coolguy
Technically your Fee model is designed incorrectly. You should have 
separate models for 'fees' and 'fees_paid' where fee would have been the 
foreign key in 'fees_paid. Fee should have a property like annual fee etc 
for each student as fee may be different based on student discounts etc. 
Then when student pays the fees, fees should go in a separate transactional 
table i.e. 'fees paid'. In your scenario, does each row in fee table 
carries the annual/school fee? if so then yes summing them up will 
definitely cause incorrect figure.

Here is what i would do if i don't change my models structure.

views.py
===
def student_detail(request, pk):
student = Student.objects.get(id=pk)

# in your case pick the first record from fee_set
first_record = student.fee_set.first()
school_fees = first_record.school_fees

paid_fees = student.fee_set.aggregate(total_paid_fees=Sum('paid_fees'))

balance_fees =  school_fees - paid_fees["total_paid_fees"] 

context = {"student": student,
   "paid_fees": paid_fees,
   "school_fees": school_fees,
   "balance_fees": balance_fees, }

return render(request, "student_details.html", context)

template
===

Student Detail
Student name: {{ student.name }}
School fees: {{ school_fees }}
Paid fees: {{ paid_fees.total_paid_fees }}
Remaining fees: {{ balance_fees }}


Output:


Student name: student1

School fees: 10.0

Paid fees: 35000.0

Remaining fees: 65000.0

On Friday, September 11, 2020 at 5:25:28 AM UTC-4 dex9...@gmail.com wrote:

> Sorry for bothering you @coolguy, you’re the only person who seems to be 
> nice to a Django beginner developer like me, and I would like to bother you 
> one more time
>
> Your solution for using methods in models is perfectly fine
>
> You see I want school_fees to be a fixed amount, example $300
>
> So when a student pays more than once(student.fee_set), lets say this 
> month student 1 pays $50 
>
> And another month pays $100 dollars, I want payments to added and 
> subtracted from fixed schools_fees($300)
>
> Remainingfees to be $300 – (($50)+($100))
>
>  
>
> BUT what “ 
> fees = student.fee_set.aggregate(total_paid_fees=Sum('paid_fees'), 
> total_school_fees=Sum('school_fees'))” 
> does is that it sums both paid fees school fees every time a student pays, 
> I want only paid fees to added every time a student pays but not school fees
>
>  
>
>  
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Friday, September 11, 2020 4:27 AM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> If i choose to go with your way of calculation, i would do this...
>
>  
>
> def student_detail(request, pk):
>
> student = Student.objects.get(id=pk)
>
>
> fees = student.fee_set.aggregate(total_paid_fees=Sum('paid_fees'), 
> total_school_fees=Sum('school_fees'))
>
>  
>
> balance_fees = fees["total_school_fees"] - fees["total_paid_fees"]
>
>  
>
> context = {"student": student, 
> "fees": fees, "balance_fees": balance_fees, }
>
>  
>
> return render(request, "student_details.html", context)
>
>  
>
> Template e.g.
>
> 
>
> Student Detail
>
> Student name: {{ student.name }}
>
> School fees: {{ fees.total_school_fees }}
>
> Paid fees: {{ fees.total_paid_fees }}
>
> Remaining fees: {{ balance_fees }}
>
> 
>
>  
>
> Result:
>
> Student Detail
>
> Student name: student1
>
> School fees: 10.0
>
> Paid fees: 25000.0
>
> Remaining fees: 75000.0
>
> I hope this helps!
>
> On Thursday, September 10, 2020 at 2:16:27 PM UTC-4 dex9...@gmail.com 
> wrote:
>
> Thanks for helping me @coolguy,but it seems I ran into another problem, 
> the school fees and remaining fees somehow sums together, I want students 
> to pay school fees in phases, i.e, first quarter, second etc, and I want 
> remaining fee to be the difference between the initial school fees which is 
> 100 and total fee paid.
>
> Thanks in advance
>
>  
>
> My views.py for student
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Tuesday, September 8, 2020 11:58 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> I see now what you are asking...
>
>  
>
> I never do such calculations in views rather I create methods i

Re: Help me with the view please

2020-09-10 Thread coolguy
If i choose to go with your way of calculation, i would do this...

def student_detail(request, pk):
student = Student.objects.get(id=pk)
fees = student.fee_set.aggregate(total_paid_fees=Sum('paid_fees'), 
total_school_fees=Sum('school_fees'))

balance_fees = fees["total_school_fees"] - fees["total_paid_fees"]

context = {"student": student, 
"fees": fees, "balance_fees": balance_fees, }

return render(request, "student_details.html", context)

Template e.g.

Student Detail
Student name: {{ student.name }}
School fees: {{ fees.total_school_fees }}
Paid fees: {{ fees.total_paid_fees }}
Remaining fees: {{ balance_fees }}


Result:
Student Detail

Student name: student1

School fees: 10.0

Paid fees: 25000.0

Remaining fees: 75000.0
I hope this helps!
On Thursday, September 10, 2020 at 2:16:27 PM UTC-4 dex9...@gmail.com wrote:

> Thanks for helping me @coolguy,but it seems I ran into another problem, 
> the school fees and remaining fees somehow sums together, I want students 
> to pay school fees in phases, i.e, first quarter, second etc, and I want 
> remaining fee to be the difference between the initial school fees which is 
> 100 and total fee paid.
>
> Thanks in advance
>
>  
>
> My views.py for student
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Tuesday, September 8, 2020 11:58 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> I see now what you are asking...
>
>  
>
> I never do such calculations in views rather I create methods in models.py 
> to do so and call them in the template...
>
>  
>
> Like what you could do is..
>
>  
>
> class Student(models.Model):
>
> name = models.CharField(max_length=200, null=True, blank=True)
>
> classroom = models.ForeignKey(Classroom,
>
>
>   on_delete=models.DO_NOTHING, blank=True, 
> null=True)
>
>  
>
> def __str__(self):
>
> return *self*.name
>
>  
>
> def get_total_fee(self):
>
> return sum(student.school_fees for student in *self*
> .fee_set.all())
>
>  
>
> def get_total_paid_fee(self):
>
> return sum(student.paid_fees for student in *self*.fee_set.all())
>
>  
>
> def get_remaining_fee(self):
>
> total_fee = *self*.get_total_fee()
>
>     total_paid = *self*.get_total_paid_fee()
>
> return float(total_fee - total_paid)
>
>  
>
> and in template you can call...
>
> {{ student.get_remaining_fee }}
>
> On Tuesday, September 8, 2020 at 1:35:56 PM UTC-4 dex9...@gmail.com wrote:
>
> Thank you for your help @coolguy..but my real problem lies in writing the 
> code for “fee_remaining”, can you help me with that also..thanks
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Tuesday, September 8, 2020 7:45 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> In your return line of code, you are referring to context variable but I 
> don't see you assigned any value to this context variable in your code.
>
> Or if you want to send three variables i.e. "fees", "total_fees" and 
> "fee_remaining"... you need to send them separately like
>
>  
>
> return render(request, 'website/students.html', {"fees": fees, 
> "total_fees": total_fees, "fee_remaining": fee_remaining })
>
>  
>
> then use these variables on your students.html template.  
>
>  
>
> On Tuesday, September 8, 2020 at 12:21:21 PM UTC-4 dex9...@gmail.com 
> wrote:
>
> My Models
> class Student(models.Model):
> name = models.CharField(max_length=200, null=True, blank=True)
> classroom = models.ForeignKey(‘Classroom’,
> on_delete=models.DO_NOTHING,blank=True, null=True)
> class Classroom(models.Model):
> name = models.CharField(max_length=40,blank=True, null=True)
>
> class Fee(models.Model):
> student = models.ForeignKey(Student, on_delete=models.CASCADE, null=True,)
> classroom = models.ForeignKey(Classroom, on_delete=models.CASCADE, 
> null=True)
> school_fees = models.FloatField(default=100)
> paid_fees = models.FloatField(null=False)
> remaining_fees = models.FloatField(blank=True)
> completed = models.BooleanField(null=False, default=False)
>
> views.py
> def student(request, pk):
> student = Student.objects.get(id=pk)
>
> fees = student.fee_set.all().order_by('-publish_date') tot

Re: Help me with the view please

2020-09-10 Thread coolguy
Can you please share the template you are using.
You can send another context variable for remaining fee.

On Thursday, September 10, 2020 at 2:16:27 PM UTC-4 dex9...@gmail.com wrote:

> Thanks for helping me @coolguy,but it seems I ran into another problem, 
> the school fees and remaining fees somehow sums together, I want students 
> to pay school fees in phases, i.e, first quarter, second etc, and I want 
> remaining fee to be the difference between the initial school fees which is 
> 100 and total fee paid.
>
> Thanks in advance
>
>  
>
> My views.py for student
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Tuesday, September 8, 2020 11:58 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> I see now what you are asking...
>
>  
>
> I never do such calculations in views rather I create methods in models.py 
> to do so and call them in the template...
>
>  
>
> Like what you could do is..
>
>  
>
> class Student(models.Model):
>
> name = models.CharField(max_length=200, null=True, blank=True)
>
> classroom = models.ForeignKey(Classroom,
>
>
>   on_delete=models.DO_NOTHING, blank=True, 
> null=True)
>
>  
>
> def __str__(self):
>
> return *self*.name
>
>  
>
> def get_total_fee(self):
>
> return sum(student.school_fees for student in *self*
> .fee_set.all())
>
>  
>
> def get_total_paid_fee(self):
>
> return sum(student.paid_fees for student in *self*.fee_set.all())
>
>  
>
> def get_remaining_fee(self):
>
> total_fee = *self*.get_total_fee()
>
> total_paid = *self*.get_total_paid_fee()
>
>     return float(total_fee - total_paid)
>
>  
>
> and in template you can call...
>
> {{ student.get_remaining_fee }}
>
> On Tuesday, September 8, 2020 at 1:35:56 PM UTC-4 dex9...@gmail.com wrote:
>
> Thank you for your help @coolguy..but my real problem lies in writing the 
> code for “fee_remaining”, can you help me with that also..thanks
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Tuesday, September 8, 2020 7:45 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> In your return line of code, you are referring to context variable but I 
> don't see you assigned any value to this context variable in your code.
>
> Or if you want to send three variables i.e. "fees", "total_fees" and 
> "fee_remaining"... you need to send them separately like
>
>  
>
> return render(request, 'website/students.html', {"fees": fees, 
> "total_fees": total_fees, "fee_remaining": fee_remaining })
>
>  
>
> then use these variables on your students.html template.  
>
>  
>
> On Tuesday, September 8, 2020 at 12:21:21 PM UTC-4 dex9...@gmail.com 
> wrote:
>
> My Models
> class Student(models.Model):
> name = models.CharField(max_length=200, null=True, blank=True)
> classroom = models.ForeignKey(‘Classroom’,
> on_delete=models.DO_NOTHING,blank=True, null=True)
> class Classroom(models.Model):
> name = models.CharField(max_length=40,blank=True, null=True)
>
> class Fee(models.Model):
> student = models.ForeignKey(Student, on_delete=models.CASCADE, null=True,)
> classroom = models.ForeignKey(Classroom, on_delete=models.CASCADE, 
> null=True)
> school_fees = models.FloatField(default=100)
> paid_fees = models.FloatField(null=False)
> remaining_fees = models.FloatField(blank=True)
> completed = models.BooleanField(null=False, default=False)
>
> views.py
> def student(request, pk):
> student = Student.objects.get(id=pk)
>
> fees = student.fee_set.all().order_by('-publish_date') total_fees = 
> student.fee_set.all().filter(student__id=pk) 
> .aggregate(sum=Sum('paid_fees', flat=True)['sum'] 
>
> fees_remaining = () 
>
> return render(request, 'website/students.html', context)  
>
> -- 
> 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/e026b778-bac8-4522-ad1f-2ea4b33ad1efn%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/e026b778-bac8-4522-ad1f-2ea4b33ad1efn%40googlegroups.com?utm_

Re: Help me with the view please

2020-09-10 Thread coolguy
Since you didn't share the template screen shot i can't say what you are 
using there for remaining fee. Anyways, you are sending two context 
variables 'fees' and 'total_fees'... you can either calculate it on 
template {{ fees - total_fees }} or you can send another context variable 
from your view.

  

On Thursday, September 10, 2020 at 2:16:27 PM UTC-4 dex9...@gmail.com wrote:

> Thanks for helping me @coolguy,but it seems I ran into another problem, 
> the school fees and remaining fees somehow sums together, I want students 
> to pay school fees in phases, i.e, first quarter, second etc, and I want 
> remaining fee to be the difference between the initial school fees which is 
> 100 and total fee paid.
>
> Thanks in advance
>
>  
>
> My views.py for student
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Tuesday, September 8, 2020 11:58 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> I see now what you are asking...
>
>  
>
> I never do such calculations in views rather I create methods in models.py 
> to do so and call them in the template...
>
>  
>
> Like what you could do is..
>
>  
>
> class Student(models.Model):
>
> name = models.CharField(max_length=200, null=True, blank=True)
>
> classroom = models.ForeignKey(Classroom,
>
>
>   on_delete=models.DO_NOTHING, blank=True, 
> null=True)
>
>  
>
> def __str__(self):
>
> return *self*.name
>
>  
>
> def get_total_fee(self):
>
> return sum(student.school_fees for student in *self*
> .fee_set.all())
>
>  
>
> def get_total_paid_fee(self):
>
> return sum(student.paid_fees for student in *self*.fee_set.all())
>
>  
>
> def get_remaining_fee(self):
>
> total_fee = *self*.get_total_fee()
>
> total_paid = *self*.get_total_paid_fee()
>
>     return float(total_fee - total_paid)
>
>  
>
> and in template you can call...
>
> {{ student.get_remaining_fee }}
>
> On Tuesday, September 8, 2020 at 1:35:56 PM UTC-4 dex9...@gmail.com wrote:
>
> Thank you for your help @coolguy..but my real problem lies in writing the 
> code for “fee_remaining”, can you help me with that also..thanks
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Tuesday, September 8, 2020 7:45 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> In your return line of code, you are referring to context variable but I 
> don't see you assigned any value to this context variable in your code.
>
> Or if you want to send three variables i.e. "fees", "total_fees" and 
> "fee_remaining"... you need to send them separately like
>
>  
>
> return render(request, 'website/students.html', {"fees": fees, 
> "total_fees": total_fees, "fee_remaining": fee_remaining })
>
>  
>
> then use these variables on your students.html template.  
>
>  
>
> On Tuesday, September 8, 2020 at 12:21:21 PM UTC-4 dex9...@gmail.com 
> wrote:
>
> My Models
> class Student(models.Model):
> name = models.CharField(max_length=200, null=True, blank=True)
> classroom = models.ForeignKey(‘Classroom’,
> on_delete=models.DO_NOTHING,blank=True, null=True)
> class Classroom(models.Model):
> name = models.CharField(max_length=40,blank=True, null=True)
>
> class Fee(models.Model):
> student = models.ForeignKey(Student, on_delete=models.CASCADE, null=True,)
> classroom = models.ForeignKey(Classroom, on_delete=models.CASCADE, 
> null=True)
> school_fees = models.FloatField(default=100)
> paid_fees = models.FloatField(null=False)
> remaining_fees = models.FloatField(blank=True)
> completed = models.BooleanField(null=False, default=False)
>
> views.py
> def student(request, pk):
> student = Student.objects.get(id=pk)
>
> fees = student.fee_set.all().order_by('-publish_date') total_fees = 
> student.fee_set.all().filter(student__id=pk) 
> .aggregate(sum=Sum('paid_fees', flat=True)['sum'] 
>
> fees_remaining = () 
>
> return render(request, 'website/students.html', context)  
>
> -- 
> 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/djan

Re: I got this error "ValueError: attempted relative import beyond top-level package "

2020-09-08 Thread coolguy
I did this long time ago and here is what i did...

in settings.py
SITE_ID = 1
# Application definition
INSTALLED_APPS = [
   # ...
   'django.contrib.sites',
   'django.contrib.sitemaps',
]

run migration i.e. 
>>> py manage.py migrateOR python manage.py migrate
after this step, sites application will be in sync with the database.

create a file sitemaps.py in your blog application. Your sitemap.py seems 
okay to me.

update your main project urls.py file

from django.contrib.sitemaps.views import sitemap
from blog.sitemaps import BlogPostsSitemap

sitemaps = {
'posts' : BlogPostsSitemap,
}

urlpatterns = [
  
  path('sitemap.xml', sitemap, {'sitemaps': sitemaps},  
name='django.contrib.sitemaps.views.sitemap'),
]

Now run the development server and open (assuming you are using default 
configuration) http://127.0.0.1:8000/sitemap

lets try...

On Tuesday, September 8, 2020 at 2:53:12 PM UTC-4 hanz...@gmail.com wrote:

> I followed a tutorial for creating django sitemap, but still got problems 
> along the way. 
> I've seen some videos, but didn't work.  
> Do you have any references for easy way creating django sitemap for blog 
> posts?
> Sure it would help. 
>
> Thanks
>
>
>
> On Wed, Sep 9, 2020 at 12:02 AM coolguy  wrote:
>
>> Not sure why you are importing this into your main project urls.py but 
>> its very straight forward
>>
>> from blog.sitemaps import BlogPostsSitemap
>>
>> question... are you trying to map the application url here? then you 
>> should use path('/' , Include("blog.urls"))
>>
>>
>>
>>
>> On Tuesday, September 8, 2020 at 4:39:05 AM UTC-4 hanz...@gmail.com 
>> wrote:
>>
>>> Sorry, point no 1 needs to be revised..
>>> 1. In urls.py, I want to import BlogPostsSitemap
>>>
>>>
>>> -- 
>> 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 view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/0f74b537-3fa8-4725-8098-b602417ea41bn%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/0f74b537-3fa8-4725-8098-b602417ea41bn%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/030f483b-fb0c-428c-ab8d-8e7d3b82eb40n%40googlegroups.com.


Re: Help me with the view please

2020-09-08 Thread coolguy
I see now what you are asking...

I never do such calculations in views rather I create methods in models.py 
to do so and call them in the template...

Like what you could do is...

class Student(models.Model):
name = models.CharField(max_length=200, null=True, blank=True)
classroom = models.ForeignKey(Classroom,
  on_delete=models.DO_NOTHING, blank=True, 
null=True)

def __str__(self):
return self.name

def get_total_fee(self):
return sum(student.school_fees for student in self.fee_set.all())

def get_total_paid_fee(self):
return sum(student.paid_fees for student in self.fee_set.all())

def get_remaining_fee(self):
total_fee = self.get_total_fee()
total_paid = self.get_total_paid_fee()
return float(total_fee - total_paid)

and in template you can call e.g
{% for student in students %}
{{ student.name }}: {{ student.get_remaining_fee }}

{% endfor %}


On Tuesday, September 8, 2020 at 1:35:56 PM UTC-4 dex9...@gmail.com wrote:

> Thank you for your help @coolguy..but my real problem lies in writing the 
> code for “fee_remaining”, can you help me with that also..thanks
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Tuesday, September 8, 2020 7:45 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> In your return line of code, you are referring to context variable but I 
> don't see you assigned any value to this context variable in your code.
>
> Or if you want to send three variables i.e. "fees", "total_fees" and 
> "fee_remaining"... you need to send them separately like
>
>  
>
> return render(request, 'website/students.html', {"fees": fees, 
> "total_fees": total_fees, "fee_remaining": fee_remaining })
>
>  
>
> then use these variables on your students.html template.  
>
>  
>
> On Tuesday, September 8, 2020 at 12:21:21 PM UTC-4 dex9...@gmail.com 
> wrote:
>
> My Models
> class Student(models.Model):
> name = models.CharField(max_length=200, null=True, blank=True)
> classroom = models.ForeignKey(‘Classroom’,
> on_delete=models.DO_NOTHING,blank=True, null=True)
> class Classroom(models.Model):
> name = models.CharField(max_length=40,blank=True, null=True)
>
> class Fee(models.Model):
> student = models.ForeignKey(Student, on_delete=models.CASCADE, null=True,)
> classroom = models.ForeignKey(Classroom, on_delete=models.CASCADE, 
> null=True)
> school_fees = models.FloatField(default=100)
> paid_fees = models.FloatField(null=False)
> remaining_fees = models.FloatField(blank=True)
> completed = models.BooleanField(null=False, default=False)
>
> views.py
> def student(request, pk):
> student = Student.objects.get(id=pk)
>
> fees = student.fee_set.all().order_by('-publish_date') total_fees = 
> student.fee_set.all().filter(student__id=pk) 
> .aggregate(sum=Sum('paid_fees', flat=True)['sum'] 
>
> fees_remaining = () 
>
> return render(request, 'website/students.html', context)  
>
> -- 
> 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/e026b778-bac8-4522-ad1f-2ea4b33ad1efn%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/e026b778-bac8-4522-ad1f-2ea4b33ad1efn%40googlegroups.com?utm_medium=email_source=footer>
> .
>
>  
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fa0084c8-5c21-4f46-82f1-23cbb8abe1can%40googlegroups.com.


Re: Help me with the view please

2020-09-08 Thread coolguy
I see now what you are asking...

I never do such calculations in views rather I create methods in models.py 
to do so and call them in the template...

Like what you could do is...

class Student(models.Model):
name = models.CharField(max_length=200, null=True, blank=True)
classroom = models.ForeignKey(Classroom,
  on_delete=models.DO_NOTHING, blank=True, 
null=True)

def __str__(self):
return self.name

def get_total_fee(self):
return sum(student.school_fees for student in self.fee_set.all())

def get_total_paid_fee(self):
return sum(student.paid_fees for student in self.fee_set.all())

def get_remaining_fee(self):
total_fee = self.get_total_fee()
total_paid = self.get_total_paid_fee()
return float(total_fee - total_paid)

and in template you can call...
{{ student.get_remaining_fee }}
On Tuesday, September 8, 2020 at 1:35:56 PM UTC-4 dex9...@gmail.com wrote:

> Thank you for your help @coolguy..but my real problem lies in writing the 
> code for “fee_remaining”, can you help me with that also..thanks
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *coolguy
> *Sent: *Tuesday, September 8, 2020 7:45 PM
> *To: *Django users
> *Subject: *Re: Help me with the view please
>
>  
>
> In your return line of code, you are referring to context variable but I 
> don't see you assigned any value to this context variable in your code.
>
> Or if you want to send three variables i.e. "fees", "total_fees" and 
> "fee_remaining"... you need to send them separately like
>
>  
>
> return render(request, 'website/students.html', {"fees": fees, 
> "total_fees": total_fees, "fee_remaining": fee_remaining })
>
>  
>
> then use these variables on your students.html template.  
>
>  
>
> On Tuesday, September 8, 2020 at 12:21:21 PM UTC-4 dex9...@gmail.com 
> wrote:
>
> My Models
> class Student(models.Model):
> name = models.CharField(max_length=200, null=True, blank=True)
> classroom = models.ForeignKey(‘Classroom’,
> on_delete=models.DO_NOTHING,blank=True, null=True)
> class Classroom(models.Model):
> name = models.CharField(max_length=40,blank=True, null=True)
>
> class Fee(models.Model):
> student = models.ForeignKey(Student, on_delete=models.CASCADE, null=True,)
> classroom = models.ForeignKey(Classroom, on_delete=models.CASCADE, 
> null=True)
> school_fees = models.FloatField(default=100)
> paid_fees = models.FloatField(null=False)
> remaining_fees = models.FloatField(blank=True)
> completed = models.BooleanField(null=False, default=False)
>
> views.py
> def student(request, pk):
> student = Student.objects.get(id=pk)
>
> fees = student.fee_set.all().order_by('-publish_date') total_fees = 
> student.fee_set.all().filter(student__id=pk) 
> .aggregate(sum=Sum('paid_fees', flat=True)['sum'] 
>
> fees_remaining = () 
>
> return render(request, 'website/students.html', context)  
>
> -- 
> 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/e026b778-bac8-4522-ad1f-2ea4b33ad1efn%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/e026b778-bac8-4522-ad1f-2ea4b33ad1efn%40googlegroups.com?utm_medium=email_source=footer>
> .
>
>  
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bc5f52f8-4b46-40c5-8ff1-9d05e3095346n%40googlegroups.com.


Re: I got this error "ValueError: attempted relative import beyond top-level package "

2020-09-08 Thread coolguy
Not sure why you are importing this into your main project urls.py but its 
very straight forward

from blog.sitemaps import BlogPostsSitemap

question... are you trying to map the application url here? then you should 
use path('/' , Include("blog.urls"))




On Tuesday, September 8, 2020 at 4:39:05 AM UTC-4 hanz...@gmail.com wrote:

> Sorry, point no 1 needs to be revised..
> 1. In urls.py, I want to import BlogPostsSitemap
>
>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0f74b537-3fa8-4725-8098-b602417ea41bn%40googlegroups.com.


Re: Help me with the view please

2020-09-08 Thread coolguy
In your return line of code, you are referring to context variable but I 
don't see you assigned any value to this context variable in your code.
Or if you want to send three variables i.e. "fees", "total_fees" and 
"fee_remaining"... you need to send them separately like

return render(request, 'website/students.html', {"fees": fees, 
"total_fees": total_fees, "fee_remaining": fee_remaining })

then use these variables on your students.html template.  


On Tuesday, September 8, 2020 at 12:21:21 PM UTC-4 dex9...@gmail.com wrote:

> My Models
> class Student(models.Model):
> name = models.CharField(max_length=200, null=True, blank=True)
> classroom = models.ForeignKey(‘Classroom’,
> on_delete=models.DO_NOTHING,blank=True, null=True)
> class Classroom(models.Model):
> name = models.CharField(max_length=40,blank=True, null=True)
>
> class Fee(models.Model):
> student = models.ForeignKey(Student, on_delete=models.CASCADE, null=True,)
> classroom = models.ForeignKey(Classroom, on_delete=models.CASCADE, 
> null=True)
> school_fees = models.FloatField(default=100)
> paid_fees = models.FloatField(null=False)
> remaining_fees = models.FloatField(blank=True)
> completed = models.BooleanField(null=False, default=False)
>
> views.py
> def student(request, pk):
> student = Student.objects.get(id=pk)
> fees = student.fee_set.all().order_by('-publish_date') total_fees = 
> student.fee_set.all().filter(student__id=pk) 
> .aggregate(sum=Sum('paid_fees', flat=True)['sum'] 
> fees_remaining = () 
> return render(request, 'website/students.html', context)  
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e026b778-bac8-4522-ad1f-2ea4b33ad1efn%40googlegroups.com.


Re: NoReverseMatch at /searchlit/customsearch and bigger problem of exporting a filtered queryset

2020-08-28 Thread coolguy
You can't have the same name twice. You need to change the name for one of 
the followings:
path('customsearch/', views.search, name='search'),
path('customsearch//', views.search, name='search_xxx')

Reverse method requires a url identified by name parameter which must be 
unique. Its looking for search and it find it on two places so you are 
getting this error.

On Friday, August 28, 2020 at 7:06:09 PM UTC-4 pcar...@gmail.com wrote:

> Hello All!  I need some help with a problem I have been struggling with.  
> One of you generous geniuses has the answer I'm sure of it.  I am working 
> on integrating an export to csv button(link) on my template to export 
> filtered data from one of my tables.  I have previously only been able to 
> dump the entire table to csv which isn't exactly what I need.  So my 
> thoughts were to place a button/link on the template passes a 
> parameter(dictionary of my filter criteria) to a view named ExportSearch.  
> The view then calls a function that I have defined to perform my filtered 
> query to the table and then writes outs to csv.  In theory I thought this 
> should work but I keep getting errors that I have not been able to resolve 
> and I am at the end of my knowledge capacity here.  Applicable code below.  
> Did I mention THANK YOU
>
> *From searchLit/urls.py*
> from django.urls import include, path
> from . import views
> from .views import search
>
> app_name= "searchLit"
>
> urlpatterns=[
> path('customsearch/', views.search, name='search'),
> path('customsearch//', views.search, name='search'),
> path('noccustomsearch/', views.nocSearch, name='nocSearch'),
> path('nocreport/export/', views.noc_export, name='noc_export'),
> path('customsearch/export/', views.searchLit_export, 
> name='SearchLit_export'),
> path('customsearch/exportSearch//', views.exportSearch, 
> name='exportSearch'),
> ]
>
> *From searchLit/views.py*
> def filterCircuits(params, search_vector):
> circuits=[]
> if(params['circuitid']==None and params['bandwidth']==None and 
> params['region']==None and params['carrier']==None and 
> params['status']==None and params['segmentname']==None and 
> params['mrcnew']==None):
> circuits=Circuitinfotable.objects.all()
> else:
> if(params['multipleSearch']!=None and 
> params['multipleSearch']!=""):
> 
> circuits=Circuitinfotable.objects.annotate(search=search_vector).filter(search=params['multipleSearch'])
> else:
> circuits = Circuitinfotable.objects.all()
> if(params['circuitid']!=None and params['circuitid']!=""):
> circuits = Circuitinfotable.objects.all()
> 
> circuits=circuits.filter(circuitid__icontains=params['circuitid'])
> if(params['bandwidth']!=None and params['bandwidth']!="" and 
> params['bandwidth']!='Select Bandwidth'):
> circuits=circuits.filter(bandwidth=params['bandwidth'])
> if(params['region']!=None and params['region']!="" and 
> params['region']!='Select Region'):
> circuits=circuits.filter(region=params['region'])
> if(params['carrier']!=None and params['carrier']!="" and 
> params['carrier']!='Select Carrier'):
> circuits=circuits.filter(carrier=params['carrier'])
> if(params['status']!=None and params['status']!="" and 
> params['status']!='Select Status'):
> circuits=circuits.filter(status=params['status'])
> if(params['segmentname']!=None and params['segmentname']!="" and 
> params['segmentname']!='Select Segment'):
> circuits=circuits.filter(segmentname=params['segmentname'])
> if(params['mrcnew']!=None and params['mrcnew']!=""):
> circuits=circuits.filter(mrcnew=params['mrcnew'])
> if(params['diversity']!='Select Option'):
> if(params['diversity']=='None'):
> circuits=circuits.filter(diversity=None)
> else:
> 
> circuits=circuits.filter(diversity__icontains=params['diversity'])
> if(params['kmz']!='Select YES/NO'):
> if(params['kmz']=='No'):
> circuits=circuits.filter(kmz=None)
> else:
> circuits=circuits.filter(kmz__isnull=False)
> return(circuits)
>
>
> def search(request):
> form = CircuitForm
> template =  'customsearch/customsearch.html'
> search_vector = SearchVector('circuitid', 'carrier', 'pathname', 
> 'segmentname', 'segmentid', 'alocationaddress', 'alocationcity', 'alocst', 
> 'zlocationaddress', 'zlocationcity', 'zlocst', 'handoffalocaddress', 
> 'handoffalocst',
>  'handoffaloccity', 'handoffzlocaddress', 
> 'handoffzloccity', 'handoffzlocst', 'latestjiraticket', 
> 'installciopsticket', 'retermciopsticket', 'discociopsticket', 'notes', 
> 'diversitynotes')
>
> params={'circuitid': request.GET.get('circuitid'),
> 'bandwidth': request.GET.get('bandwidth'),
> 

Re: NoReverseMatch at /searchlit/customsearch and bigger problem of exporting a filtered queryset

2020-08-28 Thread coolguy
You can't have the same name twice. You need to change the name for one of 
the followings:
path('customsearch/', views.search, name='search'),
path('customsearch//', views.search, name='search_xxx')

On Friday, August 28, 2020 at 7:06:09 PM UTC-4 pcar...@gmail.com wrote:

> Hello All!  I need some help with a problem I have been struggling with.  
> One of you generous geniuses has the answer I'm sure of it.  I am working 
> on integrating an export to csv button(link) on my template to export 
> filtered data from one of my tables.  I have previously only been able to 
> dump the entire table to csv which isn't exactly what I need.  So my 
> thoughts were to place a button/link on the template passes a 
> parameter(dictionary of my filter criteria) to a view named ExportSearch.  
> The view then calls a function that I have defined to perform my filtered 
> query to the table and then writes outs to csv.  In theory I thought this 
> should work but I keep getting errors that I have not been able to resolve 
> and I am at the end of my knowledge capacity here.  Applicable code below.  
> Did I mention THANK YOU
>
> *From searchLit/urls.py*
> from django.urls import include, path
> from . import views
> from .views import search
>
> app_name= "searchLit"
>
> urlpatterns=[
> path('customsearch/', views.search, name='search'),
> path('customsearch//', views.search, name='search'),
> path('noccustomsearch/', views.nocSearch, name='nocSearch'),
> path('nocreport/export/', views.noc_export, name='noc_export'),
> path('customsearch/export/', views.searchLit_export, 
> name='SearchLit_export'),
> path('customsearch/exportSearch//', views.exportSearch, 
> name='exportSearch'),
> ]
>
> *From searchLit/views.py*
> def filterCircuits(params, search_vector):
> circuits=[]
> if(params['circuitid']==None and params['bandwidth']==None and 
> params['region']==None and params['carrier']==None and 
> params['status']==None and params['segmentname']==None and 
> params['mrcnew']==None):
> circuits=Circuitinfotable.objects.all()
> else:
> if(params['multipleSearch']!=None and 
> params['multipleSearch']!=""):
> 
> circuits=Circuitinfotable.objects.annotate(search=search_vector).filter(search=params['multipleSearch'])
> else:
> circuits = Circuitinfotable.objects.all()
> if(params['circuitid']!=None and params['circuitid']!=""):
> circuits = Circuitinfotable.objects.all()
> 
> circuits=circuits.filter(circuitid__icontains=params['circuitid'])
> if(params['bandwidth']!=None and params['bandwidth']!="" and 
> params['bandwidth']!='Select Bandwidth'):
> circuits=circuits.filter(bandwidth=params['bandwidth'])
> if(params['region']!=None and params['region']!="" and 
> params['region']!='Select Region'):
> circuits=circuits.filter(region=params['region'])
> if(params['carrier']!=None and params['carrier']!="" and 
> params['carrier']!='Select Carrier'):
> circuits=circuits.filter(carrier=params['carrier'])
> if(params['status']!=None and params['status']!="" and 
> params['status']!='Select Status'):
> circuits=circuits.filter(status=params['status'])
> if(params['segmentname']!=None and params['segmentname']!="" and 
> params['segmentname']!='Select Segment'):
> circuits=circuits.filter(segmentname=params['segmentname'])
> if(params['mrcnew']!=None and params['mrcnew']!=""):
> circuits=circuits.filter(mrcnew=params['mrcnew'])
> if(params['diversity']!='Select Option'):
> if(params['diversity']=='None'):
> circuits=circuits.filter(diversity=None)
> else:
> 
> circuits=circuits.filter(diversity__icontains=params['diversity'])
> if(params['kmz']!='Select YES/NO'):
> if(params['kmz']=='No'):
> circuits=circuits.filter(kmz=None)
> else:
> circuits=circuits.filter(kmz__isnull=False)
> return(circuits)
>
>
> def search(request):
> form = CircuitForm
> template =  'customsearch/customsearch.html'
> search_vector = SearchVector('circuitid', 'carrier', 'pathname', 
> 'segmentname', 'segmentid', 'alocationaddress', 'alocationcity', 'alocst', 
> 'zlocationaddress', 'zlocationcity', 'zlocst', 'handoffalocaddress', 
> 'handoffalocst',
>  'handoffaloccity', 'handoffzlocaddress', 
> 'handoffzloccity', 'handoffzlocst', 'latestjiraticket', 
> 'installciopsticket', 'retermciopsticket', 'discociopsticket', 'notes', 
> 'diversitynotes')
>
> params={'circuitid': request.GET.get('circuitid'),
> 'bandwidth': request.GET.get('bandwidth'),
> 'region': request.GET.get('region'),
> 'carrier': request.GET.get('carrier'),
> 'status': request.GET.get('status'),
> 'segmentname': 

Re: syntax error while trying to run '$ django-admin startproject mysite' command on command terminal

2020-08-17 Thread coolguy
Hi Mike, since you didn't mention the exact error... just make sure you 
activated virtual environment and installed django in the directory you are 
in...

On Sunday, August 16, 2020 at 4:17:56 PM UTC-4, Michael O wrote:
>
> hello, i cd into the directory by cd\ to start a project and was welcomed 
> by the blinking '...'. i then typed $  $ django-admin startproject mysite 
> and I go syntax Error: invalid syntax. please help by pointing me in the 
> right direction so that I could continue to learn. Thank you.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9939f7c7-b789-4784-aef9-10ab9589b377o%40googlegroups.com.


Re:

2020-08-17 Thread coolguy
Send us the project folder screen shot where we can see the app folder and 
its sub folders. Also send us the screen shot of your view.py and urls.py

On Friday, August 14, 2020 at 10:02:39 AM UTC-4, Suraj Kumar wrote:
>
> Hi guys,
>
> I am to new django.
>
> I am making blog website project. During the making blog website I am 
> stuck one point for last 5 hrs, I don't know how to resolve this. I also 
> searched in google, stackoverflow but I am not satisfied with their answer. 
> So, anyone can help me to resolve this issue.
>
> Please find attached screenshot which given below
>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c4c6cef9-5506-4649-9950-9576cd73eb15o%40googlegroups.com.


Re: 'str' object has no attribute '_meta'

2020-08-02 Thread coolguy
please provide some details. It's pretty vague at this time.

On Sunday, August 2, 2020 at 6:12:33 PM UTC-4, Giovanni Silva wrote:
>
>
>
> -- 
> *Giovanni Silva*
> (31) 9 9532-1877
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/693e920e-de08-47ad-869d-6a0c450d9127o%40googlegroups.com.


Re: static folder does not work

2020-07-30 Thread coolguy
Does it work to change the background of your page? 

or its not working with regards to bootstrap.css...

Also check if you've accidentally commented out  The 
'django.contrib.staticfiles' 
in settings.py under INSTALLED_APP 

On Thursday, July 30, 2020 at 9:37:23 AM UTC-4, waqar khan wrote:
>
> *I have created Django Project.*
> *Project Name :- NoteBlog*
> *Application-Name :- BlogApp*
>
> *Problem:-  I have created inside application static folder and i am give 
> perfect path But does not work style.css file , How can achieve  this 
> problem.*
>
>
>
>
> *My Project Structure*
>
>
> [image: p.jpg]
>
>
>  
>
>  
>
>
>
>
>
> *style.css file*
>
> [image: s.jpg]
>
>
>
> *HTML File base.html  this is basic html file*
>
>
> [image: j1.jpg]
>
>
>
>
>
> *I am extends file base.html file extend suuccess But style.css file does 
> not work *
> *Home.html*
>
> [image: p2.jpg]
>
>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/62526ac1-e749-45d0-a0c3-699e6ce2e73fo%40googlegroups.com.


Re: Can't get rid of "CSRF verification failed. Request aborted.: when submit form with nothing selected

2020-07-29 Thread coolguy
By default, Django checks for the CSRF token in all POST requests. Remember 
to include the csrf_token tag in all forms that are submitted via POST.

Place csrf_token within form tag...
e.g.

   {% csrf_token%}
 tag

On Wednesday, July 29, 2020 at 9:57:41 PM UTC-4, Christian Seberino wrote:
>
> Here is my template...
>
> {% extends "html_base" %}
> {% block body_elements %}
>
> 
> 
> UPDATE STATUSES
> 
> {% for e in both %}
> 
> 
> {{e.0.customer.first}}
> {{e.0.customer.last}}
> 
> 
> {{e.0.date|date:"Y-m-d"}}
> 
> 
> 
> {{e.0.time|time:"h:i A"}}
> 
> {{e.1}} Completed
> 
> {% endfor %}
> 
> 
> 
>
> Go Back To Admin Page
>
> {% csrf_token %}
> 
>
> {% endblock %}
>
>
> Here is the view
>
> def admin_status(request):
> appts = [e for e in APPT.objects.all() if e.status != "Completed"]
> appts = sorted(appts,
>key = lambda a : a.customer.last + a.customer.first 
> +   \
> str(a.date) + 
> str(a.time))
> if request.method == "POST":
> form = grandmas4hire.forms.StatusForm(request.POST)
>
> if form.is_valid():
> # Need to enter more code here when this page 
> works...
> reply = django.shortcuts.redirect("/admin_status")
> else:
> both  = [(e, form.fields[str(e.id)]) for e in 
> appts]
> reply = django.shortcuts.render(request,
> 
> "admin_status.html",
> {"both" : both})
> else:
> form  = grandmas4hire.forms.StatusForm()
> both  = [(e, form[str(e.id)]) for e in appts]
> reply = django.shortcuts.render(request,
> "admin_status.html",
> {"both" : both})
>
> return reply
>
>
> Here is the dynamic form StatusForm
>
> class StatusForm(django.forms.Form):
> def __init__(self, *args, **kwargs):
> super().__init__(*args, **kwargs)
> for e in grandmas4hire.models.Appointment.objects.all():
> self.fields[str(e.id)] = 
>   \
>django.forms.BooleanField(required = 
> False)
>
>
> (I need to make a dynamic form because I needed 1 field for each 
> Appointment object.)
>
> Chris
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/925bb0d1-2510-4c88-bf05-d0501999a5e1o%40googlegroups.com.


Re: Can't get rid of "CSRF verification failed. Request aborted.: when submit form with nothing selected

2020-07-29 Thread coolguy
By default, Django checks for the CSRF token in all POST requests. Remember 
to include the csrf_token tag in all forms that are submitted via POST.

Please place csrf_token in  tag. You have placed it outside of form 
tag.

On Wednesday, July 29, 2020 at 9:57:41 PM UTC-4, Christian Seberino wrote:
>
> Here is my template...
>
> {% extends "html_base" %}
> {% block body_elements %}
>
> 
> 
> UPDATE STATUSES
> 
> {% for e in both %}
> 
> 
> {{e.0.customer.first}}
> {{e.0.customer.last}}
> 
> 
> {{e.0.date|date:"Y-m-d"}}
> 
> 
> 
> {{e.0.time|time:"h:i A"}}
> 
> {{e.1}} Completed
> 
> {% endfor %}
> 
> 
> 
>
> Go Back To Admin Page
>
> {% csrf_token %}
> 
>
> {% endblock %}
>
>
> Here is the view
>
> def admin_status(request):
> appts = [e for e in APPT.objects.all() if e.status != "Completed"]
> appts = sorted(appts,
>key = lambda a : a.customer.last + a.customer.first 
> +   \
> str(a.date) + 
> str(a.time))
> if request.method == "POST":
> form = grandmas4hire.forms.StatusForm(request.POST)
>
> if form.is_valid():
> # Need to enter more code here when this page 
> works...
> reply = django.shortcuts.redirect("/admin_status")
> else:
> both  = [(e, form.fields[str(e.id)]) for e in 
> appts]
> reply = django.shortcuts.render(request,
> 
> "admin_status.html",
> {"both" : both})
> else:
> form  = grandmas4hire.forms.StatusForm()
> both  = [(e, form[str(e.id)]) for e in appts]
> reply = django.shortcuts.render(request,
> "admin_status.html",
> {"both" : both})
>
> return reply
>
>
> Here is the dynamic form StatusForm
>
> class StatusForm(django.forms.Form):
> def __init__(self, *args, **kwargs):
> super().__init__(*args, **kwargs)
> for e in grandmas4hire.models.Appointment.objects.all():
> self.fields[str(e.id)] = 
>   \
>django.forms.BooleanField(required = 
> False)
>
>
> (I need to make a dynamic form because I needed 1 field for each 
> Appointment object.)
>
> Chris
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bf5f876f-746f-4efd-bdd0-8510ab0ca426o%40googlegroups.com.


Re: Can't get rid of "CSRF verification failed. Request aborted.: when submit form with nothing selected

2020-07-29 Thread coolguy
No. What i said the link you sent gives the validation error since fields 
are blank. Its not working the same way as you. Can you send the code for 
your html template.

On Wednesday, July 29, 2020 at 6:53:29 PM UTC-4, Christian Seberino wrote:
>
>
>
> On Wednesday, July 29, 2020 at 5:29:53 PM UTC-5, coolguy wrote:
>>
>> Tired your link for the form. If this is the form you are concerned about 
>> then the message that pops up is for validation i.e. form.is_valid().
>>
>
> Did you see the CSRF error I got?.  Here is a pic 
> https://imgur.com/a/LIRBadQ
>
> Are you saying that CSRF message is due to my view code and how I validate 
> the form?
>
> cs 
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/69e12344-1974-4440-8cd9-a195a631eab5o%40googlegroups.com.


Re: Can't get rid of "CSRF verification failed. Request aborted.: when submit form with nothing selected

2020-07-29 Thread coolguy
No. What i said the link you sent gives the validation error since fields 
are blank. Its nothing working the same way as you. Can you send the code 
for your html template.

On Wednesday, July 29, 2020 at 6:53:29 PM UTC-4, Christian Seberino wrote:
>
>
>
> On Wednesday, July 29, 2020 at 5:29:53 PM UTC-5, coolguy wrote:
>>
>> Tired your link for the form. If this is the form you are concerned about 
>> then the message that pops up is for validation i.e. form.is_valid().
>>
>
> Did you see the CSRF error I got?.  Here is a pic 
> https://imgur.com/a/LIRBadQ
>
> Are you saying that CSRF message is due to my view code and how I validate 
> the form?
>
> cs 
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/cfa26c1f-69fe-4197-a70b-a92ba5522ebco%40googlegroups.com.


Re: How to create a link between Posts List View and Items List View of the same User

2020-07-29 Thread coolguy
Please share the project directory structure. Send a screen shot or write 
it. Tnx

On Tuesday, July 28, 2020 at 11:14:14 PM UTC-4, Ahmed Khairy wrote:
>
> I am creating a project where there are Posts and Items, 2 different 
> models in 2 different apps and each has a user who can be the same.
>
> I have created a page for each user to post all related posts called 
> Userpost List view, and I want to add an if statement or a queryset to show 
> a button to link the items related to the same user called Designerpost 
> List view.
>
> I don't know how to proceed as I can fix the NoReverse Error
>
> Here is the models.py
>
> class Post(models.Model):
> designer = models.ForeignKey(User, on_delete=models.CASCADE)
> title = models.CharField(max_length=100)
>
> Here is the views.py
>
> class UserPostListView(ListView):
> model = Post
> template_name = "user_posts.html"
> context_object_name = 'posts'
> queryset = Post.objects.filter(admin_approved=True)
> paginate_by = 6
>
> def get_queryset(self):
> user = get_object_or_404(User, username=self.kwargs.get('username'))
> return Post.objects.filter(designer=user, 
> admin_approved=True).order_by('-date_posted')
>
> Here is the template user_posts.html
>
> {% if item %}
>  Go to items{% else %}
>   
> Go to 
> items
>  {% endif %}
>
> here is the item models.py
>
> class Item(models.Model):
> designer = models.ForeignKey(
> User, on_delete=models.CASCADE)
> title = models.CharField(max_length=100)
>
> here is the designerlist views.py that I am trying to link to from the 
> user post view if it is available
>
> class DesignerPostListView(ListView):
> model = Item
> template_name = "designer_posts.html"
> context_object_name = 'items'
> paginate_by = 6
>
> def get_queryset(self):
> user = get_object_or_404(User, username=self.kwargs.get('username'))
> return Item.objects.filter(designer=user).order_by('-timestamp')
>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/85ea4fa1-2eab-4c18-8a67-8769a3711f92o%40googlegroups.com.


Re: Can't get rid of "CSRF verification failed. Request aborted.: when submit form with nothing selected

2020-07-29 Thread coolguy
Tired your link for the form. If this is the form you are concerned about 
then the message that pops up is for validation i.e. form.is_valid().

On Wednesday, July 29, 2020 at 4:55:33 PM UTC-4, Christian Seberino wrote:
>
> I have a Django app with multiple forms on various pages.  They all work 
> except for one with just an optional checkbox...
>
> I checked and they all have templates with {% csrf_token %}.
>
> The only thing special but the problematic form is that I have a checkbox 
> input that is optional.
>
> That means I'm pressing the submit button when NOTHING has been selected.
>
> Can that cause this CSRF error?
>
> Thanks!
>
> Chris
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d28c9055-08d9-4eb6-8c9f-8ea245a46e3co%40googlegroups.com.


Re: want to take input of datetimefield from my template

2020-07-13 Thread coolguy
Please share your model, view and template for more clarity. Thanks

On Sunday, July 12, 2020 at 9:25:16 AM UTC-4, Chander shekhar wrote:
>
>
> On Sun, Jul 12, 2020, 6:37 PM Kasper Laudrup  > wrote:
>
>> On July 12, 2020 3:02:00 PM GMT+02:00, Chander shekhar > > wrote:
>> >starttime=datetimefield()
>> >
>> >i want to take datetimefield from my template but i am not able to do
>> >it.
>> >i have created the form and passed the widget of datetime-local but it
>> >is 
>> >not acceptable ,it is giving me error .
>> >Help me to resolve it .
>> >It's important 
>>
>> It will be a lot easier for people to help you if you share which kind of 
>> error you are getting.
>>
>> Kind regards,
>>
>> Kasper Laudrup
>>
>> -- 
>> 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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/7D0D33A0-8A01-48F7-9928-A8465CC40066%40stacktrace.dk
>> .
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a485f092-32df-42c4-a25b-dc6f1696bbdbo%40googlegroups.com.


Re: Django how get Post details using slug

2020-07-03 Thread coolguy
One more thing. if your view code is indented exactly the way it is in the 
provided then you need to fix the indentation of 

def post_details_view(request, post):

This should be under class SearchResultsViews()

like this...

class SearchResultsViews(ListView):
model = Post
template_name = 'Search.html'

def get_queryset(self):
query = self.request.GET.get('q')
object_list = Post.objects.filter(Q(title__icontains=query))
return object_list


def post_details_view(request, post):
f = get_object_or_404(Post, slug=post)
return render(request, 'post_details.html', {'f': f})


On Friday, July 3, 2020 at 5:10:14 PM UTC-4, Tanni Seriki wrote:
>
> Please let me know if you have seen the file.
> Am sorry am sending it to you as file, my phone is malfunctioning
>
> On Fri, Jul 3, 2020, 9:49 PM Tanni Seriki  > wrote:
>
>> Sir here it's all the project, currently my phone camera has fault please 
>> help me out.
>>
>> On Fri, Jul 3, 2020, 9:23 PM coolguy > > wrote:
>>
>>> I am away at this time but can you send the project urls.py screen shot 
>>> as well.
>>>
>>> On Friday, July 3, 2020 at 4:09:01 PM UTC-4, Tanni Seriki wrote:
>>>>
>>>> Here is my WhatsApp number
>>>> +2348095594236
>>>> Please I really need to solve this out
>>>>
>>>> On Fri, Jul 3, 2020, 9:07 PM Tanni Seriki  wrote:
>>>>
>>>>> Coolguy
>>>>> Please can we chat on WhatsApp...
>>>>> The post details is really giving me headache, please help out 
>>>>>
>>>>> On Fri, Jul 3, 2020, 9:04 PM coolguy  wrote:
>>>>>
>>>>>> Seems pretty simple unless you have specific question about something.
>>>>>>
>>>>>> You have a model which has some fields including Slug field which 
>>>>>> should be unique i.e. unique=True but your screen shot is not clear..
>>>>>>
>>>>>> In views you are overriding the get_queryset() method of base class 
>>>>>> and assigning it to query variable for the 'q' from http GET request. 
>>>>>> Then 
>>>>>> filtering Post data with the values in query object you have just 
>>>>>> created. 
>>>>>> Finally returned the revised object_list including this new query 
>>>>>> context.
>>>>>>
>>>>>> In post_detail_views you are retrieving data from Post based on the 
>>>>>> post slug and assigning it to variable 'f'. Finally you used the 
>>>>>> render() 
>>>>>> shortcut to render the retrieved post using a template.
>>>>>>
>>>>>> In your urlpatterns you have defined the path for your post_detail 
>>>>>> which send the post as a slug to your view and in turn view returns the 
>>>>>> HTTP response.
>>>>>>
>>>>>> On Friday, July 3, 2020 at 11:10:22 AM UTC-4, Tanni Seriki wrote:
>>>>>>>
>>>>>>> Please can someone put me through on this, post details view either 
>>>>>>> one the function based view or class based view. 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...@googlegroups.com.
>>>>>> To view this discussion on the web visit 
>>>>>> https://groups.google.com/d/msgid/django-users/d2457503-b332-4f26-8f8a-cda32934419fo%40googlegroups.com
>>>>>>  
>>>>>> <https://groups.google.com/d/msgid/django-users/d2457503-b332-4f26-8f8a-cda32934419fo%40googlegroups.com?utm_medium=email_source=footer>
>>>>>> .
>>>>>>
>>>>> -- 
>>> 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...@googlegroups.com .
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/bd9d5723-7eed-4334-9d6c-de5a076883ebo%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/django-users/bd9d5723-7eed-4334-9d6c-de5a076883ebo%40googlegroups.com?utm_medium=email_source=footer>
>>> .
>>>
>>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6bc99e96-0830-4e23-9482-cd4268c14329o%40googlegroups.com.


Re: Django how get Post details using slug

2020-07-03 Thread coolguy
if the new urls is the main url then its not correctly setup. you have to 
mention the app name

Let assume you are app name 'student' in your project. So the main urls.py 
will have it as follow:

path('students/',  include(students.urls),


This way you are telling Django to handover all the requests sent in with 
students/ to students urls.py in students directory. There is where you will 
handle this and other students related urls.


In urls.py of students app you should have as follow:

path('/', views.post_details_view, name='post_details'),



On Friday, July 3, 2020 at 5:10:14 PM UTC-4, Tanni Seriki wrote:
>
> Please let me know if you have seen the file.
> Am sorry am sending it to you as file, my phone is malfunctioning
>
> On Fri, Jul 3, 2020, 9:49 PM Tanni Seriki  > wrote:
>
>> Sir here it's all the project, currently my phone camera has fault please 
>> help me out.
>>
>> On Fri, Jul 3, 2020, 9:23 PM coolguy > > wrote:
>>
>>> I am away at this time but can you send the project urls.py screen shot 
>>> as well.
>>>
>>> On Friday, July 3, 2020 at 4:09:01 PM UTC-4, Tanni Seriki wrote:
>>>>
>>>> Here is my WhatsApp number
>>>> +2348095594236
>>>> Please I really need to solve this out
>>>>
>>>> On Fri, Jul 3, 2020, 9:07 PM Tanni Seriki  wrote:
>>>>
>>>>> Coolguy
>>>>> Please can we chat on WhatsApp...
>>>>> The post details is really giving me headache, please help out 
>>>>>
>>>>> On Fri, Jul 3, 2020, 9:04 PM coolguy  wrote:
>>>>>
>>>>>> Seems pretty simple unless you have specific question about something.
>>>>>>
>>>>>> You have a model which has some fields including Slug field which 
>>>>>> should be unique i.e. unique=True but your screen shot is not clear..
>>>>>>
>>>>>> In views you are overriding the get_queryset() method of base class 
>>>>>> and assigning it to query variable for the 'q' from http GET request. 
>>>>>> Then 
>>>>>> filtering Post data with the values in query object you have just 
>>>>>> created. 
>>>>>> Finally returned the revised object_list including this new query 
>>>>>> context.
>>>>>>
>>>>>> In post_detail_views you are retrieving data from Post based on the 
>>>>>> post slug and assigning it to variable 'f'. Finally you used the 
>>>>>> render() 
>>>>>> shortcut to render the retrieved post using a template.
>>>>>>
>>>>>> In your urlpatterns you have defined the path for your post_detail 
>>>>>> which send the post as a slug to your view and in turn view returns the 
>>>>>> HTTP response.
>>>>>>
>>>>>> On Friday, July 3, 2020 at 11:10:22 AM UTC-4, Tanni Seriki wrote:
>>>>>>>
>>>>>>> Please can someone put me through on this, post details view either 
>>>>>>> one the function based view or class based view. 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...@googlegroups.com.
>>>>>> To view this discussion on the web visit 
>>>>>> https://groups.google.com/d/msgid/django-users/d2457503-b332-4f26-8f8a-cda32934419fo%40googlegroups.com
>>>>>>  
>>>>>> <https://groups.google.com/d/msgid/django-users/d2457503-b332-4f26-8f8a-cda32934419fo%40googlegroups.com?utm_medium=email_source=footer>
>>>>>> .
>>>>>>
>>>>> -- 
>>> 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...@googlegroups.com .
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/bd9d5723-7eed-4334-9d6c-de5a076883ebo%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/django-users/bd9d5723-7eed-4334-9d6c-de5a076883ebo%40googlegroups.com?utm_medium=email_source=footer>
>>> .
>>>
>>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/157d848d-f368-4917-a337-d4b3d0623777o%40googlegroups.com.


Re: Django how get Post details using slug

2020-07-03 Thread coolguy
I am away at this time but can you send the project urls.py screen shot as 
well.

On Friday, July 3, 2020 at 4:09:01 PM UTC-4, Tanni Seriki wrote:
>
> Here is my WhatsApp number
> +2348095594236
> Please I really need to solve this out
>
> On Fri, Jul 3, 2020, 9:07 PM Tanni Seriki  > wrote:
>
>> Coolguy
>> Please can we chat on WhatsApp...
>> The post details is really giving me headache, please help out 
>>
>> On Fri, Jul 3, 2020, 9:04 PM coolguy > > wrote:
>>
>>> Seems pretty simple unless you have specific question about something.
>>>
>>> You have a model which has some fields including Slug field which should 
>>> be unique i.e. unique=True but your screen shot is not clear..
>>>
>>> In views you are overriding the get_queryset() method of base class and 
>>> assigning it to query variable for the 'q' from http GET request. Then 
>>> filtering Post data with the values in query object you have just created. 
>>> Finally returned the revised object_list including this new query context.
>>>
>>> In post_detail_views you are retrieving data from Post based on the post 
>>> slug and assigning it to variable 'f'. Finally you used the render() 
>>> shortcut to render the retrieved post using a template.
>>>
>>> In your urlpatterns you have defined the path for your post_detail which 
>>> send the post as a slug to your view and in turn view returns the HTTP 
>>> response.
>>>
>>> On Friday, July 3, 2020 at 11:10:22 AM UTC-4, Tanni Seriki wrote:
>>>>
>>>> Please can someone put me through on this, post details view either one 
>>>> the function based view or class based view. 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...@googlegroups.com .
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/d2457503-b332-4f26-8f8a-cda32934419fo%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/django-users/d2457503-b332-4f26-8f8a-cda32934419fo%40googlegroups.com?utm_medium=email_source=footer>
>>> .
>>>
>>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bd9d5723-7eed-4334-9d6c-de5a076883ebo%40googlegroups.com.


Re: Django how get Post details using slug

2020-07-03 Thread coolguy
Seems pretty simple unless you have specific question about something.

You have a model which has some fields including Slug field which should be 
unique i.e. unique=True but your screen shot is not clear..

In views you are overriding the get_queryset() method of base class and 
assigning it to query variable for the 'q' from http GET request. Then 
filtering Post data with the values in query object you have just created. 
Finally returned the revised object_list including this new query context.

In post_detail_views you are retrieving data from Post based on the post 
slug and assigning it to variable 'f'. Finally you used the render() 
shortcut to render the retrieved post using a template.

In your urlpatterns you have defined the path for your post_detail which 
send the post as a slug to your view and in turn view returns the HTTP 
response.

On Friday, July 3, 2020 at 11:10:22 AM UTC-4, Tanni Seriki wrote:
>
> Please can someone put me through on this, post details view either one 
> the function based view or class based view. 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d2457503-b332-4f26-8f8a-cda32934419fo%40googlegroups.com.