ORA-00918 error (column ambiguously defined) Django 4.1

2023-03-07 Thread Mark McWiggins
We're getting this Oracle error from the Django line:

File 
"/home/aotemp/myvenv/lib/python3.8/site-packages/django/db/backends/utils.py", 
line 89, in _execute
return self.cursor.execute(sql, params)
  File 
"/home/aotemp/myvenv/lib/python3.8/site-packages/django/db/backends/oracle/base.py",
 
line 556, in execute
return self.cursor.execute(query, self._param_generator(params))
cx_Oracle.DatabaseError: ORA-00918: column ambiguously defined

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

Traceback (most recent call last):
  File 
"/home/aotemp/myvenv/lib/python3.8/site-packages/django/core/handlers/exception.py",
 
line 56, in inner
response = get_response(request)
  File 
"/home/aotemp/myvenv/lib/python3.8/site-packages/django/core/handlers/base.py", 
line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File 
"/home/aotemp/myvenv/lib/python3.8/site-packages/django/contrib/auth/decorators.py",
 
line 23, in _wrapped_view
return view_func(request, *args, **kwargs)
  File 
"/home/aotemp/new-personality-server-2.0/personality/stores/views.py", line 
154, in store_show
store_obj = 
Store.objects.select_related('address','brand','store_status','pos_app','timezone','business_line','store_type').get(id=pk)
  File 
"/home/aotemp/myvenv/lib/python3.8/site-packages/django/db/models/query.py", 
line 646, in get
num = len(clone)
  File 
"/home/aotemp/myvenv/lib/python3.8/site-packages/django/db/models/query.py", 
line 376, in __len__
self._fetch_all()
  File 
"/home/aotemp/myvenv/lib/python3.8/site-packages/django/db/models/query.py", 
line 1867, in _fetch_all
self._result_cache = list(self._iterable_class(self))
  File 
"/home/aotemp/myvenv/lib/python3.8/site-packages/django/db/models/query.py", 
line 87, in __iter__
results = compiler.execute_sql(
  File 
"/home/aotemp/myvenv/lib/python3.8/site-packages/django/db/models/sql/compiler.py",
 
line 1398, in execute_sql
cursor.execute(sql, params)
  File 
"/home/aotemp/myvenv/lib/python3.8/site-packages/django/db/backends/utils.py", 
line 102, in execute
return super().execute(sql, params)
  File 
"/home/aotemp/myvenv/lib/python3.8/site-packages/django/db/backends/utils.py", 
line 67, in execute
return self._execute_with_wrappers(
  File 
"/home/aotemp/myvenv/lib/python3.8/site-packages/django/db/backends/utils.py", 
line 80, in _execute_with_wrappers
return executor(sql, params, many, context)
  File 
"/home/aotemp/myvenv/lib/python3.8/site-packages/django/db/backends/utils.py", 
line 89, in _execute
return self.cursor.execute(sql, params)
  File 
"/home/aotemp/myvenv/lib/python3.8/site-packages/django/db/utils.py", line 
91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
  File 
"/home/aotemp/myvenv/lib/python3.8/site-packages/django/db/backends/utils.py", 
line 89, in _execute
return self.cursor.execute(sql, params)
  File 
"/home/aotemp/myvenv/lib/python3.8/site-packages/django/db/backends/oracle/base.py",
 
line 556, in execute
return self.cursor.execute(query, self._param_generator(params))
django.db.utils.DatabaseError: ORA-00918: column ambiguously defined

The particular line of code that triggers it is:

   store_obj = 
Store.objects.select_related('address','brand','store_status','pos_app','timezone','business_line','store_type').\
get(id=pk)

I understand that the error is an indication of the same column names in 
different tables, but for me the ORM is obscuring how to fix this problem 
in this case.

Any ideas? I'd appreciate any way to debug this that you have a suggestion.

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/7762f859-668b-4a65-9199-ccffd2334ecan%40googlegroups.com.


Re: Trying to render images from database

2023-03-07 Thread Michael Starr
I am using FireFox.

On Tuesday, March 7, 2023 at 2:11:38 PM UTC-8 Michael Starr wrote:

> this.window.gBrowserInit is undefined ext-browser.js:1134
> get activeTab chrome://browser/content/parent/ext-browser.js:1134
> candidates chrome://extensions/content/parent/ext-tabs-base.js:2091
> next self-hosted:1743
> query chrome://extensions/content/parent/ext-tabs-base.js:2113
> next self-hosted:1743
> from self-hosted:516
> query chrome://browser/content/parent/ext-tabs.js:1000
> query self-hosted:1359
> result resource://gre/modules/ExtensionParent.jsm:1156
> withCallContextData resource://gre/modules/ExtensionParent.jsm:639
> result resource://gre/modules/ExtensionParent.jsm:1155
> withPendingBrowser resource://gre/modules/ExtensionParent.jsm:649
> result resource://gre/modules/ExtensionParent.jsm:1154
> callAndLog resource://gre/modules/ExtensionParent.jsm:1107
> recvAPICall resource://gre/modules/ExtensionParent.jsm:1153
> AsyncFunctionNext self-hosted:810
>
>
> On Tuesday, March 7, 2023 at 1:58:12 PM UTC-8 Red Plant wrote:
>
>> What's showing on the browser console?
>>
>> If you're using chrome, press F12 to open developer tools, then find the 
>> console tab.
>>
>> On Wed, Mar 8, 2023, 1:31 AM Michael Starr  wrote:
>>
>>> Well, my privilege of posting "" on SO was revoked so I can't get my 
>>> questions answered anymore. So I guess I just won't be a developer now. Or 
>>> the alternative, reinvent all code and the internet.
>>> The answer the dude gave me wasn't sufficient and he was like, "Accept 
>>> the answer!" Devious prick. And then he was like "share your code with me!" 
>>> And what he does is copy your code into his github account and claim he 
>>> "helped" you.
>>> Blah. What a loser.
>>> So anyway, it still shows img alt text BUT now when I upload a photo 
>>> into the pet_photo object, it appends a six digit ASCII text thingy to the 
>>> filename, so the filename isn't actually correct even, anymore.
>>> So many problems. Django is NOT the api for perfectionists with 
>>> deadlines.
>>> Mike
>>>
>>> On Saturday, March 4, 2023 at 3:31:30 PM UTC-8 Michael Starr wrote:
>>>
 Thank you Sandip. I missed that.

 In any case I have revamped the code with some help from stack overflow 
 here 
 https://stackoverflow.com/questions/75632266/displaying-an-image-stored-in-a-django-database
 However the image alt text instead of the image displays! So weird! 

 class PetOwnerDetailView(DetailView):
 model = PetOwner
 context_object_name = "owner"
 template_name = "pet_owner_profile.html"
 def get_context_data(self, *args, **kwargs):
 context = super().get_context_data(**kwargs)
 pets = Pet.objects.all()
 pet_data = {}
 for pet in pets:
 pet_data[pet] = PetPhoto.objects.filter(pets=pet)
 context['pet_data'] = pet_data
 return context

 {% extends "base.html" %}
 {% block header %}
 {% endblock %}
 {% block content %}
 {{ owner.name }}
 {{ owner.age }}
 {{ owner.location }}
 {{ owner.profile_photo }}
 {% for pet in owner.pets.all %}
 {{ pet.name }}
 {{ pet.animaltype }}
 {{ pet.age }}
 
 {{ pet.name }} Photos
 {% for pet, photos in pet_data.items %}
 {{ pet.name }}
 {% for photo in photos %}
 
 {% endfor %}
 {% endfor %}
 {% endfor %}
 {% endblock %}

 [image: Screenshot 2023-03-04 153038.png]

 So close yet so far! Argh! lol

 Mike

 On Saturday, March 4, 2023 at 1:37:26 AM UTC-8 Sandip Bhattacharya 
 wrote:

> Are you sure this is the right query? This is looking for pet owners 
> with the name “pets”. 
>
> pets = PetOwner.objects.filter(name = "pets”) 
>
> Perhaps, you mean: 
> pets = PetOwner.pets.all() 
>
> - Sandip 
>
> > On Mar 3, 2023, at 8:08 PM, Michael Starr  
> wrote: 
> > 
> > I think this solution 
> > 
> https://stackoverflow.com/questions/75632266/displaying-an-image-stored-in-a-django-database
>  
> > should work but for some reason python got messed up on my laptop 
> when I went mobile at the coffee shop. The PYTHONPATH got deleted the 
> .venv 
> environment was deleted but still displayed and I'm getting a ton of 
> system 
> bugs trying to run python makemigrations or python migrate. 
> > 
> > Frustrating. I am using the python repair tool in the python 
> installer to repair python. Will let you know if the solution works after 
> I 
> get my environment back up and workin.g 
> > On Friday, March 3, 2023 at 2:01:03 PM UTC-8 Michael Starr wrote: 
> > It's not working. 
> > class 

Re: Trying to render images from database

2023-03-07 Thread Michael Starr
this.window.gBrowserInit is undefined ext-browser.js:1134
get activeTab chrome://browser/content/parent/ext-browser.js:1134
candidates chrome://extensions/content/parent/ext-tabs-base.js:2091
next self-hosted:1743
query chrome://extensions/content/parent/ext-tabs-base.js:2113
next self-hosted:1743
from self-hosted:516
query chrome://browser/content/parent/ext-tabs.js:1000
query self-hosted:1359
result resource://gre/modules/ExtensionParent.jsm:1156
withCallContextData resource://gre/modules/ExtensionParent.jsm:639
result resource://gre/modules/ExtensionParent.jsm:1155
withPendingBrowser resource://gre/modules/ExtensionParent.jsm:649
result resource://gre/modules/ExtensionParent.jsm:1154
callAndLog resource://gre/modules/ExtensionParent.jsm:1107
recvAPICall resource://gre/modules/ExtensionParent.jsm:1153
AsyncFunctionNext self-hosted:810


On Tuesday, March 7, 2023 at 1:58:12 PM UTC-8 Red Plant wrote:

> What's showing on the browser console?
>
> If you're using chrome, press F12 to open developer tools, then find the 
> console tab.
>
> On Wed, Mar 8, 2023, 1:31 AM Michael Starr  wrote:
>
>> Well, my privilege of posting "" on SO was revoked so I can't get my 
>> questions answered anymore. So I guess I just won't be a developer now. Or 
>> the alternative, reinvent all code and the internet.
>> The answer the dude gave me wasn't sufficient and he was like, "Accept 
>> the answer!" Devious prick. And then he was like "share your code with me!" 
>> And what he does is copy your code into his github account and claim he 
>> "helped" you.
>> Blah. What a loser.
>> So anyway, it still shows img alt text BUT now when I upload a photo into 
>> the pet_photo object, it appends a six digit ASCII text thingy to the 
>> filename, so the filename isn't actually correct even, anymore.
>> So many problems. Django is NOT the api for perfectionists with deadlines.
>> Mike
>>
>> On Saturday, March 4, 2023 at 3:31:30 PM UTC-8 Michael Starr wrote:
>>
>>> Thank you Sandip. I missed that.
>>>
>>> In any case I have revamped the code with some help from stack overflow 
>>> here 
>>> https://stackoverflow.com/questions/75632266/displaying-an-image-stored-in-a-django-database
>>> However the image alt text instead of the image displays! So weird! 
>>>
>>> class PetOwnerDetailView(DetailView):
>>> model = PetOwner
>>> context_object_name = "owner"
>>> template_name = "pet_owner_profile.html"
>>> def get_context_data(self, *args, **kwargs):
>>> context = super().get_context_data(**kwargs)
>>> pets = Pet.objects.all()
>>> pet_data = {}
>>> for pet in pets:
>>> pet_data[pet] = PetPhoto.objects.filter(pets=pet)
>>> context['pet_data'] = pet_data
>>> return context
>>>
>>> {% extends "base.html" %}
>>> {% block header %}
>>> {% endblock %}
>>> {% block content %}
>>> {{ owner.name }}
>>> {{ owner.age }}
>>> {{ owner.location }}
>>> {{ owner.profile_photo }}
>>> {% for pet in owner.pets.all %}
>>> {{ pet.name }}
>>> {{ pet.animaltype }}
>>> {{ pet.age }}
>>> 
>>> {{ pet.name }} Photos
>>> {% for pet, photos in pet_data.items %}
>>> {{ pet.name }}
>>> {% for photo in photos %}
>>> >> >
>>> {% endfor %}
>>> {% endfor %}
>>> {% endfor %}
>>> {% endblock %}
>>>
>>> [image: Screenshot 2023-03-04 153038.png]
>>>
>>> So close yet so far! Argh! lol
>>>
>>> Mike
>>>
>>> On Saturday, March 4, 2023 at 1:37:26 AM UTC-8 Sandip Bhattacharya wrote:
>>>
 Are you sure this is the right query? This is looking for pet owners 
 with the name “pets”. 

 pets = PetOwner.objects.filter(name = "pets”) 

 Perhaps, you mean: 
 pets = PetOwner.pets.all() 

 - Sandip 

 > On Mar 3, 2023, at 8:08 PM, Michael Starr  
 wrote: 
 > 
 > I think this solution 
 > 
 https://stackoverflow.com/questions/75632266/displaying-an-image-stored-in-a-django-database
  
 > should work but for some reason python got messed up on my laptop 
 when I went mobile at the coffee shop. The PYTHONPATH got deleted the 
 .venv 
 environment was deleted but still displayed and I'm getting a ton of 
 system 
 bugs trying to run python makemigrations or python migrate. 
 > 
 > Frustrating. I am using the python repair tool in the python 
 installer to repair python. Will let you know if the solution works after 
 I 
 get my environment back up and workin.g 
 > On Friday, March 3, 2023 at 2:01:03 PM UTC-8 Michael Starr wrote: 
 > It's not working. 
 > class PetOwnerDetailView(DetailView): 
 > model = PetOwner 
 > context_object_name = "owner" 
 > template_name = "pet_owner_profile.html" 
 > def get_context_data(self, *args, **kwargs): 
 > context = super().get_context_data(**kwargs) 

Re: Trying to render images from database

2023-03-07 Thread Red Plant
What's showing on the browser console?

If you're using chrome, press F12 to open developer tools, then find the
console tab.

On Wed, Mar 8, 2023, 1:31 AM Michael Starr  wrote:

> Well, my privilege of posting "" on SO was revoked so I can't get my
> questions answered anymore. So I guess I just won't be a developer now. Or
> the alternative, reinvent all code and the internet.
> The answer the dude gave me wasn't sufficient and he was like, "Accept the
> answer!" Devious prick. And then he was like "share your code with me!" And
> what he does is copy your code into his github account and claim he
> "helped" you.
> Blah. What a loser.
> So anyway, it still shows img alt text BUT now when I upload a photo into
> the pet_photo object, it appends a six digit ASCII text thingy to the
> filename, so the filename isn't actually correct even, anymore.
> So many problems. Django is NOT the api for perfectionists with deadlines.
> Mike
>
> On Saturday, March 4, 2023 at 3:31:30 PM UTC-8 Michael Starr wrote:
>
>> Thank you Sandip. I missed that.
>>
>> In any case I have revamped the code with some help from stack overflow
>> here
>> https://stackoverflow.com/questions/75632266/displaying-an-image-stored-in-a-django-database
>> However the image alt text instead of the image displays! So weird!
>>
>> class PetOwnerDetailView(DetailView):
>> model = PetOwner
>> context_object_name = "owner"
>> template_name = "pet_owner_profile.html"
>> def get_context_data(self, *args, **kwargs):
>> context = super().get_context_data(**kwargs)
>> pets = Pet.objects.all()
>> pet_data = {}
>> for pet in pets:
>> pet_data[pet] = PetPhoto.objects.filter(pets=pet)
>> context['pet_data'] = pet_data
>> return context
>>
>> {% extends "base.html" %}
>> {% block header %}
>> {% endblock %}
>> {% block content %}
>> {{ owner.name }}
>> {{ owner.age }}
>> {{ owner.location }}
>> {{ owner.profile_photo }}
>> {% for pet in owner.pets.all %}
>> {{ pet.name }}
>> {{ pet.animaltype }}
>> {{ pet.age }}
>> 
>> {{ pet.name }} Photos
>> {% for pet, photos in pet_data.items %}
>> {{ pet.name }}
>> {% for photo in photos %}
>> 
>> {% endfor %}
>> {% endfor %}
>> {% endfor %}
>> {% endblock %}
>>
>> [image: Screenshot 2023-03-04 153038.png]
>>
>> So close yet so far! Argh! lol
>>
>> Mike
>>
>> On Saturday, March 4, 2023 at 1:37:26 AM UTC-8 Sandip Bhattacharya wrote:
>>
>>> Are you sure this is the right query? This is looking for pet owners
>>> with the name “pets”.
>>>
>>> pets = PetOwner.objects.filter(name = "pets”)
>>>
>>> Perhaps, you mean:
>>> pets = PetOwner.pets.all()
>>>
>>> - Sandip
>>>
>>> > On Mar 3, 2023, at 8:08 PM, Michael Starr  wrote:
>>> >
>>> > I think this solution
>>> >
>>> https://stackoverflow.com/questions/75632266/displaying-an-image-stored-in-a-django-database
>>> > should work but for some reason python got messed up on my laptop when
>>> I went mobile at the coffee shop. The PYTHONPATH got deleted the .venv
>>> environment was deleted but still displayed and I'm getting a ton of system
>>> bugs trying to run python makemigrations or python migrate.
>>> >
>>> > Frustrating. I am using the python repair tool in the python installer
>>> to repair python. Will let you know if the solution works after I get my
>>> environment back up and workin.g
>>> > On Friday, March 3, 2023 at 2:01:03 PM UTC-8 Michael Starr wrote:
>>> > It's not working.
>>> > class PetOwnerDetailView(DetailView):
>>> > model = PetOwner
>>> > context_object_name = "owner"
>>> > template_name = "pet_owner_profile.html"
>>> > def get_context_data(self, *args, **kwargs):
>>> > context = super().get_context_data(**kwargs)
>>> > context['pet_photos'] = {}
>>> > pets = PetOwner.objects.filter(name = "pets")
>>> > for pet in pets:
>>> > context['pet_photos'][pet] = []
>>> > for photo in pet.pet_photos:
>>> > context['pet_photos'][pet] += photo
>>> > # context['pet_photos'] = {pet1: [photo1, photo2, photo3], pet2:
>>> [photo1, photo2]}
>>> > return context
>>> >
>>> > {% extends "base.html" %}
>>> > {% block header %}
>>> > {% endblock %}
>>> > {% block content %}
>>> > {{ owner.name }}
>>> > {{ owner.age }}
>>> > {{ owner.location }}
>>> > {{ owner.profile_photo }}
>>> > {% for pet in owner.pets.all %}
>>> > {{ pet.name }}
>>> > {{ pet.animaltype }}
>>> > {{ pet.age }}
>>> > 
>>> > {% for photo in pet_photos.pet.photos %}
>>> > 
>>> > {% endfor %}
>>> > {% endfor %}
>>> > {% endblock %}
>>> >
>>> >
>>> > Nothing shows up. I've tried a million and a half ways to iterate over
>>> the data structure I've created to store pets as keys and photos in a list
>>> as values in get_context_data for 'pet_photos' but nothing ever displays.
>>> >
>>> > Then there's the question of like, are my directory structure and
>>> settings file correct.
>>> >
>>> > STATIC_URL = 

Django v3.2 broken admin interface due to malicious JSON value

2023-03-07 Thread hi via Django users
Hello everybody,

I’ve used a fuzzer on my Django v3.2 project that resulted in a broken admin 
interface. I’m not sure whether this is a bug or a rough edge case.

I’m using Python 3.9.13 with Django 3.2.18 with Postgres.

I have a Model with a JSONField and also added the model to my admin view (I 
don’t use the JSON field on the list view / filter)

```
data = models.JSONField(null=True, blank=True)
```

The fuzzer added (via an API view) a string with 10,000 characters to the data 
field. 

Every time I want to open the admin list view (and the malicious object is part 
of the page), my Django crashes with the following message:

> ValueError
> 
> Exceeds the limit (4300) for integer string conversion: value has 1 
> digits; use sys.set_int_max_str_digits() to increase the limit

I have attached my Sentry stack trace as a screenshot.

If this is an intended behavior, I have to validate the data to prevent 
malicious strings. But it feels like the admin interface should be able to 
handle those JSON values.

It looks like the Python releases in Sep 2022 have to do with this bug/edge 
case: 
https://mail.python.org/archives/list/python-...@python.org/message/B25APD6FF27NJWKTEGAFRUDNSVVAFIHQ/
 


Kind Regards,

Johannes




-- 
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/6172A96F-F5FD-4694-9597-DFA815297945%40jfilter.de.


Re: Backend In Web Programming | PHP, Laravel, ASP.NET, Django

2023-03-07 Thread Mastersoft Technology
Thanks

On Mon, Mar 6, 2023 at 9:59 PM PATRICK OFOSU AGYEMANG <
pathills2...@gmail.com> wrote:

> Hi everyone, currently looking for a remote challenging opportunity for my
> next career.
>
> Kindly find attached my CV.
>
> Let me know if any help comes up.
>
> 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/a5314098-4f11-4a64-bcdd-08e27515bc88n%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/CAN1m8aGO3fzOwGXzUQdPRU0D_tKOG8gXE3eqUO2D-35PErRMhQ%40mail.gmail.com.


Re: Trying to render images from database

2023-03-07 Thread Michael Starr
this https://docs.djangoproject.com/en/4.1/topics/files/ seems useful, but 
isn't really for me.
Mike

On Tuesday, March 7, 2023 at 9:31:02 AM UTC-8 Michael Starr wrote:

> Well, my privilege of posting "" on SO was revoked so I can't get my 
> questions answered anymore. So I guess I just won't be a developer now. Or 
> the alternative, reinvent all code and the internet.
> The answer the dude gave me wasn't sufficient and he was like, "Accept the 
> answer!" Devious prick. And then he was like "share your code with me!" And 
> what he does is copy your code into his github account and claim he 
> "helped" you.
> Blah. What a loser.
> So anyway, it still shows img alt text BUT now when I upload a photo into 
> the pet_photo object, it appends a six digit ASCII text thingy to the 
> filename, so the filename isn't actually correct even, anymore.
> So many problems. Django is NOT the api for perfectionists with deadlines.
> Mike
>
> On Saturday, March 4, 2023 at 3:31:30 PM UTC-8 Michael Starr wrote:
>
>> Thank you Sandip. I missed that.
>>
>> In any case I have revamped the code with some help from stack overflow 
>> here 
>> https://stackoverflow.com/questions/75632266/displaying-an-image-stored-in-a-django-database
>> However the image alt text instead of the image displays! So weird! 
>>
>> class PetOwnerDetailView(DetailView):
>> model = PetOwner
>> context_object_name = "owner"
>> template_name = "pet_owner_profile.html"
>> def get_context_data(self, *args, **kwargs):
>> context = super().get_context_data(**kwargs)
>> pets = Pet.objects.all()
>> pet_data = {}
>> for pet in pets:
>> pet_data[pet] = PetPhoto.objects.filter(pets=pet)
>> context['pet_data'] = pet_data
>> return context
>>
>> {% extends "base.html" %}
>> {% block header %}
>> {% endblock %}
>> {% block content %}
>> {{ owner.name }}
>> {{ owner.age }}
>> {{ owner.location }}
>> {{ owner.profile_photo }}
>> {% for pet in owner.pets.all %}
>> {{ pet.name }}
>> {{ pet.animaltype }}
>> {{ pet.age }}
>> 
>> {{ pet.name }} Photos
>> {% for pet, photos in pet_data.items %}
>> {{ pet.name }}
>> {% for photo in photos %}
>> 
>> {% endfor %}
>> {% endfor %}
>> {% endfor %}
>> {% endblock %}
>>
>> [image: Screenshot 2023-03-04 153038.png]
>>
>> So close yet so far! Argh! lol
>>
>> Mike
>>
>> On Saturday, March 4, 2023 at 1:37:26 AM UTC-8 Sandip Bhattacharya wrote:
>>
>>> Are you sure this is the right query? This is looking for pet owners 
>>> with the name “pets”. 
>>>
>>> pets = PetOwner.objects.filter(name = "pets”) 
>>>
>>> Perhaps, you mean: 
>>> pets = PetOwner.pets.all() 
>>>
>>> - Sandip 
>>>
>>> > On Mar 3, 2023, at 8:08 PM, Michael Starr  wrote: 
>>> > 
>>> > I think this solution 
>>> > 
>>> https://stackoverflow.com/questions/75632266/displaying-an-image-stored-in-a-django-database
>>>  
>>> > should work but for some reason python got messed up on my laptop when 
>>> I went mobile at the coffee shop. The PYTHONPATH got deleted the .venv 
>>> environment was deleted but still displayed and I'm getting a ton of system 
>>> bugs trying to run python makemigrations or python migrate. 
>>> > 
>>> > Frustrating. I am using the python repair tool in the python installer 
>>> to repair python. Will let you know if the solution works after I get my 
>>> environment back up and workin.g 
>>> > On Friday, March 3, 2023 at 2:01:03 PM UTC-8 Michael Starr wrote: 
>>> > It's not working. 
>>> > class PetOwnerDetailView(DetailView): 
>>> > model = PetOwner 
>>> > context_object_name = "owner" 
>>> > template_name = "pet_owner_profile.html" 
>>> > def get_context_data(self, *args, **kwargs): 
>>> > context = super().get_context_data(**kwargs) 
>>> > context['pet_photos'] = {} 
>>> > pets = PetOwner.objects.filter(name = "pets") 
>>> > for pet in pets: 
>>> > context['pet_photos'][pet] = [] 
>>> > for photo in pet.pet_photos: 
>>> > context['pet_photos'][pet] += photo 
>>> > # context['pet_photos'] = {pet1: [photo1, photo2, photo3], pet2: 
>>> [photo1, photo2]} 
>>> > return context 
>>> > 
>>> > {% extends "base.html" %} 
>>> > {% block header %} 
>>> > {% endblock %} 
>>> > {% block content %} 
>>> > {{ owner.name }} 
>>> > {{ owner.age }} 
>>> > {{ owner.location }} 
>>> > {{ owner.profile_photo }} 
>>> > {% for pet in owner.pets.all %} 
>>> > {{ pet.name }} 
>>> > {{ pet.animaltype }} 
>>> > {{ pet.age }} 
>>> >  
>>> > {% for photo in pet_photos.pet.photos %} 
>>> >  
>>> > {% endfor %} 
>>> > {% endfor %} 
>>> > {% endblock %} 
>>> > 
>>> > 
>>> > Nothing shows up. I've tried a million and a half ways to iterate over 
>>> the data structure I've created to store pets as keys and photos in a list 
>>> as values in get_context_data for 'pet_photos' but nothing ever displays. 
>>> > 
>>> > Then there's the question of like, are my directory 

Re: Trying to render images from database

2023-03-07 Thread Michael Starr
Well, my privilege of posting "" on SO was revoked so I can't get my 
questions answered anymore. So I guess I just won't be a developer now. Or 
the alternative, reinvent all code and the internet.
The answer the dude gave me wasn't sufficient and he was like, "Accept the 
answer!" Devious prick. And then he was like "share your code with me!" And 
what he does is copy your code into his github account and claim he 
"helped" you.
Blah. What a loser.
So anyway, it still shows img alt text BUT now when I upload a photo into 
the pet_photo object, it appends a six digit ASCII text thingy to the 
filename, so the filename isn't actually correct even, anymore.
So many problems. Django is NOT the api for perfectionists with deadlines.
Mike

On Saturday, March 4, 2023 at 3:31:30 PM UTC-8 Michael Starr wrote:

> Thank you Sandip. I missed that.
>
> In any case I have revamped the code with some help from stack overflow 
> here 
> https://stackoverflow.com/questions/75632266/displaying-an-image-stored-in-a-django-database
> However the image alt text instead of the image displays! So weird! 
>
> class PetOwnerDetailView(DetailView):
> model = PetOwner
> context_object_name = "owner"
> template_name = "pet_owner_profile.html"
> def get_context_data(self, *args, **kwargs):
> context = super().get_context_data(**kwargs)
> pets = Pet.objects.all()
> pet_data = {}
> for pet in pets:
> pet_data[pet] = PetPhoto.objects.filter(pets=pet)
> context['pet_data'] = pet_data
> return context
>
> {% extends "base.html" %}
> {% block header %}
> {% endblock %}
> {% block content %}
> {{ owner.name }}
> {{ owner.age }}
> {{ owner.location }}
> {{ owner.profile_photo }}
> {% for pet in owner.pets.all %}
> {{ pet.name }}
> {{ pet.animaltype }}
> {{ pet.age }}
> 
> {{ pet.name }} Photos
> {% for pet, photos in pet_data.items %}
> {{ pet.name }}
> {% for photo in photos %}
> 
> {% endfor %}
> {% endfor %}
> {% endfor %}
> {% endblock %}
>
> [image: Screenshot 2023-03-04 153038.png]
>
> So close yet so far! Argh! lol
>
> Mike
>
> On Saturday, March 4, 2023 at 1:37:26 AM UTC-8 Sandip Bhattacharya wrote:
>
>> Are you sure this is the right query? This is looking for pet owners with 
>> the name “pets”. 
>>
>> pets = PetOwner.objects.filter(name = "pets”) 
>>
>> Perhaps, you mean: 
>> pets = PetOwner.pets.all() 
>>
>> - Sandip 
>>
>> > On Mar 3, 2023, at 8:08 PM, Michael Starr  wrote: 
>> > 
>> > I think this solution 
>> > 
>> https://stackoverflow.com/questions/75632266/displaying-an-image-stored-in-a-django-database
>>  
>> > should work but for some reason python got messed up on my laptop when 
>> I went mobile at the coffee shop. The PYTHONPATH got deleted the .venv 
>> environment was deleted but still displayed and I'm getting a ton of system 
>> bugs trying to run python makemigrations or python migrate. 
>> > 
>> > Frustrating. I am using the python repair tool in the python installer 
>> to repair python. Will let you know if the solution works after I get my 
>> environment back up and workin.g 
>> > On Friday, March 3, 2023 at 2:01:03 PM UTC-8 Michael Starr wrote: 
>> > It's not working. 
>> > class PetOwnerDetailView(DetailView): 
>> > model = PetOwner 
>> > context_object_name = "owner" 
>> > template_name = "pet_owner_profile.html" 
>> > def get_context_data(self, *args, **kwargs): 
>> > context = super().get_context_data(**kwargs) 
>> > context['pet_photos'] = {} 
>> > pets = PetOwner.objects.filter(name = "pets") 
>> > for pet in pets: 
>> > context['pet_photos'][pet] = [] 
>> > for photo in pet.pet_photos: 
>> > context['pet_photos'][pet] += photo 
>> > # context['pet_photos'] = {pet1: [photo1, photo2, photo3], pet2: 
>> [photo1, photo2]} 
>> > return context 
>> > 
>> > {% extends "base.html" %} 
>> > {% block header %} 
>> > {% endblock %} 
>> > {% block content %} 
>> > {{ owner.name }} 
>> > {{ owner.age }} 
>> > {{ owner.location }} 
>> > {{ owner.profile_photo }} 
>> > {% for pet in owner.pets.all %} 
>> > {{ pet.name }} 
>> > {{ pet.animaltype }} 
>> > {{ pet.age }} 
>> >  
>> > {% for photo in pet_photos.pet.photos %} 
>> >  
>> > {% endfor %} 
>> > {% endfor %} 
>> > {% endblock %} 
>> > 
>> > 
>> > Nothing shows up. I've tried a million and a half ways to iterate over 
>> the data structure I've created to store pets as keys and photos in a list 
>> as values in get_context_data for 'pet_photos' but nothing ever displays. 
>> > 
>> > Then there's the question of like, are my directory structure and 
>> settings file correct. 
>> > 
>> > STATIC_URL = '/static/' 
>> > STATIC_ROOT = os.path.join(BASE_DIR, 'static/') 
>> > 
>> > pet_memorial/static/ is the file path. I don't know if that's right or 
>> it needs to be in the project sub-directory. It's impossible to figure this 
>> out online. No one explains 

Don't pass a "set" object in the choices argument for a model field

2023-03-07 Thread Tj Johnson
I just ran into this, a field will accept a "set" object for the choices 
argument, however since set objects are unordered, it's possible that a new 
migration will be created every single time makemigrations is run.

debugging this was a matter of noticing that the developer used curly 
braces instead of parentheses or brackets, it could have been very sticky.  
Wondering if this should raise a TypeError


-- 
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/8b1364f4-8c06-49b3-87c6-e9073ddb1e3en%40googlegroups.com.


Threading and Async Views

2023-03-07 Thread Vasanth Mohan
Hello,

I'm currently building a multitenant service on django that uses a separate 
DB configuration per tenant. The frontend adds a unique header along with 
their requests so that the app can identify the tenant and select the DB to 
be used.

The catch is the tenant reference is stored as a thread local variable, so 
that the DatabaseRouter can use it. 

However, I am currently looking up async views to see if it can help 
optimise our apis. Will my thread-based logic clash with the ASGI async 
views ? 

Thanks
Vasanth M

-- 
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/a2edc596-2c59-4ed2-8afe-9aff9c1ecb52n%40googlegroups.com.


Update in django value

2023-03-07 Thread Prashanth Patelc
How to update single record particular value in django..

h_date=Holiday.objects.filter(start_date=month_start,end_date=month_end).values_list('date',flat=True)

for h_date in holiday:


Model.objects.filter(emp=request.user). update(date =h_date,in_time=None)

This above query is updating all dates I want to update particular date is
available then update record..

-- 
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/CAMCU6CoHk8rsnAzijp4UFYqtv6i7Gkq74yaLXp4iXH-Puu-6XQ%40mail.gmail.com.