Django: TypeError: Calling `.seed()` on instances is deprecated. Use the class method `Faker.seed()` instead
i tried to make virtual data using django_seed. when python version was 3.7, there was no error. however, after updating python to 3.8 version there are error. what this error means?
See also questions close to this topic
How to parse boolean with config parser
Using python's builtin
configparser, I want to parse boolean values in my conf file.
[SECTION] foo = False
However, when accessing the variable I notice that it is processed as a string.
>>> config['SECTION']['foo'] 'False'
Furthermore, when I attempt to correct this behavior and reassign key
footo it's proper boolean representative, I get this error
>>> if config['SECTION']['foo'] == 'True': ... config['SECTION']['foo'] = True ... elif config['SECTION']['foo'] == 'False': ... config['SECTION']['foo'] = False ... else: ... Exception("foo must be bool") TypeError: option values must be strings
Unfortunately, this behavior leads to problematic situations where the following performs unexpectedly
print(config['SECTION']['foo']) # 'False' if config['SECTION']['foo']: print('do things when foo is True') # this runs, but foo actually # represents false, but in string form
How am I supposed to deal with booleans when parsing with
configparserwith the least amount of overhead as possible?
Can't take more than 1 proxy from the page with python code
So I have a paid proxy page which shows a different IP when you refresh the page
import smtplib import pandas as pd from time import sleep import random import requests import socks # pip install pysocks import json from requests.exceptions import ConnectionError def getProxy(): rq = requests.get( "https://proxy.com") data = json.loads(rq.content) print("IP: ", data["ip"]) print("PORT: ", int(data["port"])) return data for i in range(1,5): try: myProxy = getProxy() socks.setdefaultproxy(socks.SOCKS5, myProxy["ip"], int(myProxy["port"])) socks.wrapmodule(smtplib) print(myProxy["ip"]) print(myProxy["port"]) sleep(10) except ConnectionError as e: print (e) print('out')` here
The code works just for one proxy, after that it shows this error: HTTPSConnectionPool(host='gimmeproxy.com', port=443): Max retries exceeded with url: And also the code wouldn't take 5 proxies even when I didn't make so many tries
Django: how to control time format in DataTable?
I use DataTable in a Django project
context pass to my template : Heures.objects.all()
my problem concern heu_dat field that is display as 1 pm where 13:00:36.227396 is stored in my database
I would like to display heu_dat like 13:00:36 (french format)
class Heures(models.Model): _safedelete_policy = SOFT_DELETE_CASCADE heu_ide = models.AutoField(primary_key=True) date = models.ForeignKey(Jours, on_delete = models.CASCADE, null=True) user = models.ForeignKey(Profile, on_delete = models.CASCADE, null=True) heu_dat = models.TimeField("Heure du pointage", null=True, blank=True,auto_now_add=True) heu_cod = models.IntegerField("Code employé", null=True, blank=True) heu_com = models.CharField("Commentaires", max_length = 150, null=True, blank=True)
Should I use One-to-Many to Many-to-Many fields?
I have an opera model:
class Opera(MPTTModel): name = models.CharField(max_length=8000, null=True, blank=True) librettist = models.ForeignKey(Person, verbose_name=_('librettist'), null=True, blank=True, related_name='person', on_delete=models.PROTECT)
The structure of the Opera is a tree structure:
Opera (Top level) |--> Overture |--> Aria #1 |--> Aria #2
Each opera or aria has a cast of characters:
class Cast(models.Model): character_name = models.CharField(max_length=100, null=True, blank=True) voice_type = models.ForeignKey(Instrument, null=True, blank=True, on_delete=models.CASCADE)
There is also a mapping table to map Cast to the Opera model:
class WorkCast(models.Model): opera = models.ForeignKey(Opera, verbose_name=_('opera'), related_name='workcast', null=True, blank=True, on_delete=models.PROTECT) cast = models.ForeignKey(Cast, verbose_name=_('cast'), related_name='workcast', null=True, blank=True, on_delete=models.PROTECT)
An opera (top level) has the entire cast mapped to it. Aria #1 or Aria #2 will have a subset of cast map to it.
When I am in the admin menu, I want to be able to select the opera model and link multiple cast member to it. Does this mean that WorkCast model needs to have Many-to-many field to cast or Foreign Key to cast? It seems like I have to force a many-to-many relationship in order to use the inline feature in admin.py?