Re: View / Query Set not showing with filter

2021-03-19 Thread Arisophy
Hi Manuelf

I understand what you say.
Now, I think It's not the problem of Querym , too.
The problem is that field data is not displayed in HTML.

You use the wrong variable name "office" in Template.

try this.

(View)
context['office'] = 
↓
context['offices']  = ...

(Template)

× {% for office in office.all %}
 ↓
{% for office in offices %}


regards

Arisophy

2021年3月20日(土) 7:31 Manuel Buri :

> *Booking Model*
> from django.db import models
> from django.utils import timezone
> from users.models import Account
> from organization.models import Organization, Office
>
>
> class Booking(models.Model):
> LOCATION_OPTIONS = (
> ('H', 'Home Office'),
> ('O', 'Office'),
> ('N', 'Not indicated'),
> )
> account = models.ForeignKey(Account,
> on_delete=models.CASCADE)
> organization= models.ForeignKey(Organization,
> on_delete=models.CASCADE)
> office  = models.ForeignKey(Office,
> on_delete=models.CASCADE)
> booking_time= models.DateTimeField(default=timezone.now)
> location= models.CharField(max_length=1,
> choices=LOCATION_OPTIONS)
> class Meta:
> unique_together = ('account', 'booking_time',)
>
> *View*
> def overview_view(request):
>
> context = {}
>
> if request.method == 'GET':
> start_date = None
> end_date = None
> if request.is_ajax():
> booking_times = request.GET.get('day')
> start_date = datetime.strptime(booking_times, "%Y-%m-%d")
> end_date = start_date + timedelta(days=4)
> start_date = start_date.replace(hour=0, minute=0, second=0,
> microsecond=0, tzinfo=pytz.utc)
> end_date = end_date.replace(hour=0, minute=0, second=0,
> microsecond=0, tzinfo=pytz.utc)
>
> context['bookings']=Booking.objects.filter(
> Q(organization_id=request.user.organization_id), Q(booking_time__range =
> (start_date, end_date))
> context['office'] =
> Office.objects.filter(organization_id__exact=request.user.organization_id)
>
> return render(request, 'overview/overview.html', context)
> return render(request, 'overview/overview.html', context)
>
> haha sorry for not using pastebin before :D
>
> Thank you so much.
>
> Best wishes,
>
> Manuel
>
>
>
> Manuel Buri
> T:  +41 79 933 01 11
> M: manuel.b...@gmail.com
> W: www.manuelburi.com <http://manuelburi.com/?utm_source=gmail>
>
>
> On Fri, 19 Mar 2021 at 23:22, Héctor Alonso Lozada Echezuría <
> ima...@gmail.com> wrote:
>
>> Can you share your "Booking" model and the view (function or class) that
>> renders the template?, and I beg you, please use pastebin.com for share
>> your code :D
>>
>> El vie, 19 mar 2021 a las 16:17, Manuel Buri ()
>> escribió:
>>
>>> @anornymou...@gmail.com and ima...@gmail.com
>>> your suggestion is unfortunately not working too
>>>
>>> @All:
>>> So as said my queryset is not empty, meaning that the query works.
>>> However, the results is not in the rendered HTML file.
>>> This would imply that with my template is something wrong, don't you
>>> think?
>>>
>>> {% for office in office.all %}
>>> {{ office.office_name }}
>>> {% for booking in bookings %}
>>> 
>>> 
>>> {{ booking.account.first_name }} {{ 
>>> booking.account.last_name }}
>>> {% if booking.get_location_display == 'House' %}
>>>  {{ booking.get_location_display 
>>> }}
>>> {% elif booking.get_location_display == 'Home' %}
>>>  {{ booking.get_location_display 
>>> }}
>>> {% else %}
>>> 樂 {{ booking.get_location_display 
>>> }}
>>> {% endif %}
>>> 
>>> 
>>> {% endfor %}
>>> {% endfor %}
>>>
>>>
>>> What do you think?
>>>
>>> Thank you so much for your help !
>>>
>>> Best wishes,
>>>
>>> Manuel
>>>
>>>
>>>
>>> Manuel Buri
>>> T:  +41 79 933 01 11
>>> M: manuel.b...@gmail.com
>>> W: www.manuelburi.com <http://manuelburi.com/?utm_source=gmail>
>>>
>>>
>>> On Fri, 19 Mar 2021 at 22:51, Thomas Lockhart 
>>> wrote:
>>>
>>>> Why use Q? afaict simple filter syntax should get you what you wan

Re: 2 Almost equal Context with non-empty query set: 1 works, 1 returns nothing

2021-03-18 Thread Arisophy
use this

https://docs.djangoproject.com/ja/3.1/ref/models/querysets/#date

*.filter(booking_time__date=booking_date) *


2021年3月19日(金) 11:58 Arisophy :

> Hi Manuel
>
> Oops!
> *.filter(booking_time=booking_date) doesn't work*
>
> Did you check the query and DB data?
> Are booking_time's time of  DB data just 00:00:00?
>
> If another time, you have to use
>  booking_time >= target_date AND  booking_time < next_date_of_target
>
> Arisophy
>
> 2021年3月19日(金) 9:36 Arisophy :
>
>> Hi, Manuei
>>
>> I think ,
>> At first, you shoukd check the value of "request.user.organization_id" .
>> Next, try to use Q if the value is valid.
>>
>> context['bookings'] =
>> Booking.objects.filters(Q((organization_id=request.user.organization_id) &
>> Q(booking_time=booking_date))
>>
>>
>> https://docs.djangoproject.com/en/3.1/topics/db/queries/#complex-lookups-with-q
>>
>> regards
>>
>> Arisophy
>>
>> 2021年3月19日(金) 7:59 Manuel Buri :
>>
>>> Hi folks,
>>> can you please help me with this.
>>>
>>> I am trying to get the context working where I filter for the
>>> organization_id as well as the booking_time. Both queries are not empty,
>>> however, only the context without the booking_time filter works while
>>> rending in html.
>>>
>>> Code:
>>> @login_required
>>> def overview_view(request):
>>>
>>> context = {}
>>> booking_date = None
>>>
>>> if request.method == 'GET':
>>> if request.is_ajax():
>>> booking_time = request.GET.get('day')
>>> booking_time = datetime.strptime(booking_time, "%Y-%m-%d")
>>> booking_date = booking_time.replace(hour=0, minute=0, second=0,
>>> microsecond=0, tzinfo=pytz.utc)
>>>
>>> *THIS ONE DOES NOT WORK*
>>>
>>> *context['bookings'] =
>>> Booking.objects.filter(organization_id=request.user.organization_id).filter(
>>> booking_time=booking_date)*
>>>
>>> *THESE DO WORK:* context['bookings'] =
>>> Booking.objects.filter(organization_id=request.user.organization_id)
>>> return render(request, 'overview/overview.html', context)
>>>
>>> return render(request, 'overview/overview.html', context)
>>>
>>>
>>> Thank you so much for your help.
>>>
>>> Manuel
>>>
>>> --
>>> 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/8afb07f4-10b2-4145-ab23-6fe9bb41c599n%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/8afb07f4-10b2-4145-ab23-6fe9bb41c599n%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/CA%2B2LtkA3xDROCw7rH0cWubQ9Tq12nB0hVLASPPEtftbwADe0PQ%40mail.gmail.com.


Re: 2 Almost equal Context with non-empty query set: 1 works, 1 returns nothing

2021-03-18 Thread Arisophy
Hi Manuel

Oops!
*.filter(booking_time=booking_date) doesn't work*

Did you check the query and DB data?
Are booking_time's time of  DB data just 00:00:00?

If another time, you have to use
 booking_time >= target_date AND  booking_time < next_date_of_target

Arisophy

2021年3月19日(金) 9:36 Arisophy :

> Hi, Manuei
>
> I think ,
> At first, you shoukd check the value of "request.user.organization_id" .
> Next, try to use Q if the value is valid.
>
> context['bookings'] =
> Booking.objects.filters(Q((organization_id=request.user.organization_id) &
> Q(booking_time=booking_date))
>
>
> https://docs.djangoproject.com/en/3.1/topics/db/queries/#complex-lookups-with-q
>
> regards
>
> Arisophy
>
> 2021年3月19日(金) 7:59 Manuel Buri :
>
>> Hi folks,
>> can you please help me with this.
>>
>> I am trying to get the context working where I filter for the
>> organization_id as well as the booking_time. Both queries are not empty,
>> however, only the context without the booking_time filter works while
>> rending in html.
>>
>> Code:
>> @login_required
>> def overview_view(request):
>>
>> context = {}
>> booking_date = None
>>
>> if request.method == 'GET':
>> if request.is_ajax():
>> booking_time = request.GET.get('day')
>> booking_time = datetime.strptime(booking_time, "%Y-%m-%d")
>> booking_date = booking_time.replace(hour=0, minute=0, second=0,
>> microsecond=0, tzinfo=pytz.utc)
>>
>> *THIS ONE DOES NOT WORK*
>>
>> *context['bookings'] =
>> Booking.objects.filter(organization_id=request.user.organization_id).filter(
>> booking_time=booking_date)*
>>
>> *THESE DO WORK:* context['bookings'] =
>> Booking.objects.filter(organization_id=request.user.organization_id)
>> return render(request, 'overview/overview.html', context)
>>
>> return render(request, 'overview/overview.html', context)
>>
>>
>> Thank you so much for your help.
>>
>> Manuel
>>
>> --
>> 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/8afb07f4-10b2-4145-ab23-6fe9bb41c599n%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/8afb07f4-10b2-4145-ab23-6fe9bb41c599n%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/CA%2B2LtkBe_Cc6xftuMMrQFUXzLMtWoDoimmhB1d%2BLBrpczANYKw%40mail.gmail.com.


Re: 2 Almost equal Context with non-empty query set: 1 works, 1 returns nothing

2021-03-18 Thread Arisophy
Hi, Manuei

I think ,
At first, you shoukd check the value of "request.user.organization_id" .
Next, try to use Q if the value is valid.

context['bookings'] =
Booking.objects.filters(Q((organization_id=request.user.organization_id) &
Q(booking_time=booking_date))

https://docs.djangoproject.com/en/3.1/topics/db/queries/#complex-lookups-with-q

regards

Arisophy

2021年3月19日(金) 7:59 Manuel Buri :

> Hi folks,
> can you please help me with this.
>
> I am trying to get the context working where I filter for the
> organization_id as well as the booking_time. Both queries are not empty,
> however, only the context without the booking_time filter works while
> rending in html.
>
> Code:
> @login_required
> def overview_view(request):
>
> context = {}
> booking_date = None
>
> if request.method == 'GET':
> if request.is_ajax():
> booking_time = request.GET.get('day')
> booking_time = datetime.strptime(booking_time, "%Y-%m-%d")
> booking_date = booking_time.replace(hour=0, minute=0, second=0,
> microsecond=0, tzinfo=pytz.utc)
>
> *THIS ONE DOES NOT WORK*
>
> *context['bookings'] =
> Booking.objects.filter(organization_id=request.user.organization_id).filter(
> booking_time=booking_date)*
>
> *THESE DO WORK:* context['bookings'] =
> Booking.objects.filter(organization_id=request.user.organization_id)
> return render(request, 'overview/overview.html', context)
>
> return render(request, 'overview/overview.html', context)
>
>
> Thank you so much for your help.
>
> Manuel
>
> --
> 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/8afb07f4-10b2-4145-ab23-6fe9bb41c599n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/8afb07f4-10b2-4145-ab23-6fe9bb41c599n%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/CA%2B2LtkC9Qsf3oxm5bRLsL%2BECUtDqB_e2ycGnesB69zWkVoNhWg%40mail.gmail.com.


Re: How to programmatically set the model when using Django CreateView?

2021-01-29 Thread Arisophy
Hi Robert

Just looking at the code
Why do you change context to empty?

context = {}
return render(request, self.template_name, context)



Aisophy

2021年1月30日(土) 3:09 Robert F. :

> I am trying to programmatically set the model for a Django class-based
> view that inherits from CreateView and displays a form for creating a
> 'member' object. My problem is that  my template is not displaying the form
> itself. Note that I override the 'get' method to determine what model the
> view should use. The template page renders and I see the submit button but
> when I view the page's source code, the form is missing. Here's my code:
>
> # urls.py
> path('profile/create/', views.ProfileCreate.as_view(),
> name='profile-create'),
>
> # views.py
> class ProfileCreate(CreateView):
> model = None
> template_name = None
>
> def get(self, request, *args, **kwargs):
> member = Member.objects.get(user=request.user)
> if member.is_couple:
> self.model = ProfileCouple
> self.template_name = 'account/profile_couple_create.html'
> self.fields = ['person1_name', 'person2_name',
>'person1_dob', 'person2_dob']
> else:
> self.model = ProfileSingle
> self.template_name = 'account/profile_single_create.html'
> self.fields = ['person1_name', 'person1_dob']
>
> context = {}
> return render(request, self.template_name, context)
>
> # models.py
> class ProfileSingle(models.Model):
> user = models.OneToOneField(User, on_delete=models.CASCADE,
> null=True)
> person1_name = models.CharField(_("Name"), max_length=50)
> person1_dob = models.DateField()
>
> def __str__(self):
> return self.user.username
>
> class ProfileCouple(models.Model):
> user = models.OneToOneField(User, on_delete=models.CASCADE,
> null=True)
> person1_name = models.CharField(_("Name 1"), max_length=50)
> person1_dob = models.DateField()
> person2_name = models.CharField(_("Name 2"), max_length=50)
> person2_dob = models.DateField()
>
> def __str__(self):
> return self.user.username
>
> # forms.py
> class CreateSingleProfileForm(forms.ModelForm):
> class Meta:
> model = ProfileSingle
> fields = ('user', 'person1_name', 'person1_dob')
> labels = {'user': _('Username'), 'person1_name': _(
> 'Person 1 Name'), 'person1_dob': _('Person 1 DOB')}
>
> class CreateCoupleProfileForm(forms.ModelForm):
> class Meta:
> model = ProfileCouple
> ...
>
> # profile_single_create.html
> 
>   Create Your Profile
>   {% csrf_token %}
>   {{ form.as_p }}
>   
>   
> 
>
> # profile_couple_create.html
> (Code similar to single template)
>
> I know that with CBVs, Django will build the form for me.  But there will
> be times when I need to customize the form as I do here. What am I missing?
>
> --
> 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/6d394628-6132-4927-8324-466347c8c427n%40googlegroups.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/CA%2B2LtkB%3DBiXAzZUHiBCdtMciBKRAfCahthoaP9XXRv%2BW3zN5Ng%40mail.gmail.com.


Re: Good Django libraries to read to really understand class-based views?

2021-01-11 Thread Arisophy
Hello Robert.

Did you read class based views code?
Original django class-based view code is below.

https://github.com/django/django/tree/master/django/views/generic


I made an extension class for FormView and ListView.

https://github.com/Arisophy/django-searchview

I hope it helps you understand how to extend the call-based view .

best regards.

Arisophy

2021年1月12日(火) 0:15 Robert F. :

> Are there any Django libraries that make extensive use of class-based
> views that I might study if I want to gain an in-depth understanding of how
> to use them? The Django documentation is OK at explaining what they are and
> how they work but most of the examples are very trivial in nature. I'd like
> to become a "power user" and for that I need lots of code to study. I've
> looked at the Classy Class-Based Views <https://ccbv.co.uk/> examples but
> they seem too "meta" to me to shed any real light on how to use them in
> practice. 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/eda0feed-fb61-4882-bbc3-14531b13526fn%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/eda0feed-fb61-4882-bbc3-14531b13526fn%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/CA%2B2LtkDUkWaTAX2RXj09AgNxAknW%3Dz%2BG-SYmRj_B2zEGJf%2B4bQ%40mail.gmail.com.


Re: deployment error : django + pgsql

2020-12-29 Thread Arisophy ISJ
Hi, Govind,

Did you see this page?

https://stackoverflow.com/questions/51903606/errors-when-i-try-to-migrate-in-django2

Is that situation similar to yours?

regards,
Arisophy

2020年12月30日水曜日 6:33:13 UTC+9 jayo...@gmail.com:

> Initially my webapp was using sqlite and I tried migrate my data to 
> postgresdb by following the same procedure as mentioned in the " Dev post " 
> you just shared with me while I was deploying the webapp on nginx server 
> but it failed with error "unknown field (s) (next_post, previous_post)".
>
> After that I configured my project in postgresdb on my system from 
> begining and added all the data in postgresdb so I could easily deploy my 
> webapp, but when I tried to deploy this time I got the error message which 
> I had posted earlier.
> In simple words I'm not able to migrate in my already existing webapp(it's 
> on postgresdb on my local machine too).
> Regards,
> Govind
>
> On Wed 30 Dec, 2020, 2:39 AM Kasper Laudrup,  wrote:
>
>> Hi Govind,
>>
>> On 29/12/2020 21.57, Govind Kumar Yadav wrote:
>> > Like if I am trying to deploy a new project from beginning I am able to 
>> > do that without any error but when I try to deploy my already existing 
>> > project which works fine on my local windows machine with postgresdb it 
>> > fails to migrate the data and pops error that relation "posts_post does 
>> > not exist".
>>
>> Are you using postgres on Windows or which database are you using? It's 
>> not really clear from what you're writing, but if you're using sqlite, 
>> then this might help:
>>
>>
>> https://dev.to/coderasha/how-to-migrate-data-from-sqlite-to-postgresql-in-django-182h
>>
>> It seems like this has nothing to do with the operating system but is 
>> more of a database migration issue?
>>
>> > Please let me know that if it's possible to deploy a full fledged 
>> django 
>> > webapp with al the data prepared on local host using postgresdb on 
>> Linux.
>>
>> It is. You just need to make it clearer what you have done to "prepare 
>> all the data on localhost".
>>
>> 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-users...@googlegroups.com.
>>
> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/d722e69c-a82b-0886-ad67-d1a3165242dc%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/974e799a-a53d-4ed5-a8e7-c44e7a07eaddn%40googlegroups.com.