Re: How can i Open binary files with Django?

2023-02-13 Thread atleta

You don't open files with django. You open files with the built-in function 
'open'. Which allows you to specify text or binary mode. See the 
documentation: https://docs.python.org/3.11/library/functions.html#open
On Monday, February 13, 2023 at 9:56:18 PM UTC+1 Lucas Matos wrote:

> I tested so many ways to do it, however a only found how to open text 
> files. Someone can help me?

-- 
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/09553009-4ed2-472d-a86c-a7687308b4b9n%40googlegroups.com.


Re: Admin foreign key widgets Dont quote Keys that the unicode of the Primary key (value=number) is a special character.

2023-02-13 Thread Dev Femi Badmus
https://chat.whatsapp.com/IVvrrF9Wq7OHWk5x4XNk9K

On Wed, Feb 8, 2023 at 3:40 PM Oluwayemisi Ismail <
ismailoluwayem...@gmail.com> wrote:

> Hello everyone,
>
> I'm Working on a ticket, "Admin Foreign Key widgets don't quote keys".
> When I reproduce the bug, I realized that the widgets quote characters and
> numbers as the value of the primary key.
>
> The challenge I have is that the widgets don't quote keys with primary key
> value that is a number and the unicode of the number is a special
> character. E.g, let's assume the primary key value is _4000, and I try to
> click on the 'change' icon in the Admin site, I get the error that  ID "@"
> doesn't exist. Perhaps it was deleted?  The unicode of 40 is "@". but when
> I click on the unicode of  4000 without "_" as the prefix, I don't get the
> error. This usually happens when the number's unicode is a special
> character.
>
>  My question is, has anyone ran into this challenge before? Does anyone
> have an idea on how to go about it? below is the attached picture of the
> error, ranging from "PK1-PK3"
>
>
> --
> 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/bf527880-a175-4727-8a1b-8b04e5b24f15n%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/CAD9bWYyxP7B1uN10COv7HkJqu5psbbJdry0WTgsLqM3q3VjqAw%40mail.gmail.com.


How can i Open binary files with Django?

2023-02-13 Thread Lucas Matos
I tested so many ways to do it, however a only found how to open text 
files. Someone can help me?

-- 
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/3f339958-2338-4cea-94b3-04b6e5a342d9n%40googlegroups.com.


BlockChain and Crypto Group

2023-02-13 Thread Satyajit Barik
Guys join our Crypto WhatsApp group.
It's free for everyone. Daily 2-3 profitable trade calls.

We give the best analysis of the market price prediction.

Want to see you all as a profitable trader. Just join and celebrate拾

https://chat.whatsapp.com/IqQwOGrxBJgAIIkuC5HIBu

-- 
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/CANd-%2BoCgo7WamdvVZKpVAwOr5V52QZHDthpX2VMLoezLwg%3Dzmw%40mail.gmail.com.


Re: django model method

2023-02-13 Thread Jason
there's alot to not like about the implementation here.  You're effectively 
hiding queries and db hits with those methods, since the naming does not 
give any indication that its a db hit.  So its really easy to forget that, 
and then after a while, you're wondering why your project is so slow and 
executing alot of unnecessary queries

for seen, likes and hotness counts, I'd rather denormalize  and have a 
count field for all those values.  Then either use a post-save signal to 
update the values, or use a recurring background task to regenerate the 
fields on an interval.

On Friday, February 10, 2023 at 9:02:16 AM UTC-5 Gabriel Araya Garcia wrote:

> Allways there is a way to improve the code, but  if that not run, then try 
> with CYTHON
>
> Gabriel Araya Garcia
> GMI - Desarrollo de Sistemas Informáticos
>
>
>
>
> El jue, 9 feb 2023 a las 10:09, Andréas Kühne () 
> escribió:
>
>> Not if you want it to be fast. Python itself is slow - so you should try 
>> to offload most of the computation on the database. So filtering would need 
>> to be done on database fields as well.
>>
>> Otherwise you would need to load all of the rows into memory and then do 
>> the filtering there.
>>
>> If you want to continue along the route you have taken now - you probably 
>> could solve it with annotated queries - something like this:
>>
>> https://stackoverflow.com/questions/1396264/how-to-sort-by-annotated-count-in-a-related-model-in-django
>>
>> Regards,
>>
>> Andréas
>>
>>
>> Den tors 9 feb. 2023 kl 13:21 skrev Chelsea Fan :
>>
>>> understood, is there any way to filter objects by method value?
>>>
>>> On Thu, Feb 9, 2023 at 4:42 PM Andréas Kühne  
>>> wrote:
>>>
 No.

 Ordering works by using the database to order the models. It therefore 
 needs to be a database field - otherwise the database can't order by the 
 field?

 Regards,

 Andréas


 Den tors 9 feb. 2023 kl 12:09 skrev Chelsea Fan >>> >:

> hello guys, Is it possible to use model method value to ordering model 
> objects in meta class?
>
> class Post(models.Model):
> title = models.CharField(max_length=255, verbose_name="ady")
> text = RichTextField(verbose_name="text")
> tagList = models.ManyToManyField(Tag, verbose_name="taglar", 
> related_query_name="tagList")
> image = models.ImageField(upload_to="postImage/", verbose_name=
> "surat")
> seen = models.ManyToManyField(UserId,verbose_name="görülen sany", 
> blank=True, related_name="gorulen")
> like = models.ManyToManyField(UserId,verbose_name="like sany", 
> blank=True)
> share = models.PositiveIntegerField(verbose_name="paýlaşylan sany", 
> null=True, blank=True, default="0")
> createdAt = models.DateTimeField(auto_now_add=True, 
> verbose_name="goşulan 
> güni")
>
> class Meta:
> verbose_name_plural="Makalalar"
> # ordering = ("-createdAt",)
> ordering = ["-hotness",]
>
> def __str__(self):
> return self.title
>
> def likes(self):
> return self.like.count()
>
> likes.short_description = "Like sany"
> likes.allow_tags = True
>
> def seens(self):
> return self.seen.count()
>
> seens.short_description = "Görülen sany"
> seens.allow_tags = True
>
> @property
> def hotness(self):
> return self.likes() + self.seens() + self.share
>
> -- 
> 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/CAJwZndfmes4g2KWUB3Fz6wNRORQ40Fxj_NYwYKWCF6DX96OVyg%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/CAK4qSCfpaVQ1YXMbVae26RLgsYYBcLRMcpgQOEm9z3%2B6NpN5Ww%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 

Facing error while working on my project(google oauth2.0 logins)

2023-02-13 Thread bloomlync monisha
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
  File 
"C:\Users\bloom\AppData\Local\Programs\Python\Python311\Lib\threading.py", 
line 1038, in _bootstrap_inner
self.run()
  File 
"C:\Users\bloom\AppData\Local\Programs\Python\Python311\Lib\threading.py", 
line 975, in run
self._target(*self._args, **self._kwargs)
  File 
"C:\Users\bloom\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\autoreload.py",
 
line 64, in wrapper
fn(*args, **kwargs)
  File 
"C:\Users\bloom\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management\commands\runserver.py",
 
line 125, in inner_run
autoreload.raise_last_exception()
  File 
"C:\Users\bloom\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\autoreload.py",
 
line 87, in raise_last_exception
raise _exception[1]
  File 
"C:\Users\bloom\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management\__init__.py",
 
line 398, in execute
autoreload.check_errors(django.setup)()
  File 
"C:\Users\bloom\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\autoreload.py",
 
line 64, in wrapper
fn(*args, **kwargs)
  File 
"C:\Users\bloom\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management\commands\runserver.py",
 
line 125, in inner_r
un
autoreload.raise_last_exception()  File 
"C:\Users\bloom\AppData\Local\Programs\Python\Python311\Lib\site-pa
ckages\django\utils\autoreload.py", line 87, in raise_last_exception
raise _exception[1]
  File 
"C:\Users\bloom\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management\__init__.py",
 
line 398, in execute
autoreload.check_errors(django.setup)()
  File "C:\Users\bloom\AppData\Local\Programs\Python\Python311\Lib\site-pa
ckages\django\utils\autoreload.py", line 64, in wrapperfn(*args, 
**kwargs)
  File "C:\Users\bloom\AppData\Local\Programs\Python\Python311\Lib\site-pa
ckages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
  File "C:\Users\bloom\AppData\Local\Programs\Python\Python311\Lib\site-pa
ckages\django\apps\registry.py", line 91, in populateapp_config = 
AppConfig.create(entry)
 ^^^
  File "C:\Users\bloom\AppData\Local\Programs\Python\Python311\Lib\site-pa
ckages\django\apps\config.py", line 123, in create
mod = import_module(mod_path)  ^^^
  File 
"C:\Users\bloom\AppData\Local\Programs\Python\Python311\Lib\importlib\__init__.py",
 
line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
   
  File "", line 1206, in _gcd_import
  File "", line 1178, in _find_and_load
  File "", line 1149, in _find_and_load_unloc
ked
  File "", line 690, in _load_unlocked
  File "", line 936, in exec_module
  File "", line 1074, in get_code
  File "", line 1004, in source_to_c
ode
  File "", line 241, in _call_with_frames_rem
oved
ValueError: source code string cannot contain null bytes

-- 
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/979a22df-8893-4f12-935a-b3601f0e09acn%40googlegroups.com.


Re: TabularInlineAdmin queries waaaaaayyyyyy too much.

2023-02-13 Thread Chetan Ganji
Try them and see if it helps!

https://betterprogramming.pub/django-select-related-and-prefetch-related-f23043fd635d

Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Thu, Feb 2, 2023 at 8:53 PM Mark Jones  wrote:

> I have an admin with 1 row in the tabular inline.  I have a custom
> queryset in
>
> class ExtensionTabularInlineFormSet(BaseInlineFormSet):
> def get_queryset(self) -> QuerySet[Extension]:
> qs = super().get_queryset()
>
> This gets called 20 times to display that one row.  When you have more
> rows, it gets called 20 times/row.
>
> The culprit is calls to this method:
> def initial_form_count(self):
> """Return the number of forms that are required in this FormSet."""
> if not self.is_bound:
> return len(self.get_queryset())
> return super().initial_form_count()
>
> The solution would be to cache this value, but admin views seem like
> singletons way too often for this to work.  Anyone else seen this?
>
> --
> 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/f4bacbd9-b519-45af-8e5b-826c4b5d9c88n%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/CAMKMUjs%3D8jOG%2BziTj0a3UWpTyBss9vNqOUPLzLDG4Q876MUBVw%40mail.gmail.com.