I am writing a bot on python. At start in id are entered id, firstname, lastname, username. In the future, the user can send a phone number. Question: how to add by id? Or is it better to make a separate table with id and number and enter it there?
1 answer
Immediately create a table with columns: id, firstname, lastname, username, telephone (by default NULL), and when the user sends you a number, simply write it there.
Example:
from peewee import * class BaseModel(Model): class Meta: database = None # Π’ΡΡ ΡΠ²ΠΎΡ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅ ΠΊ ΠΠ class User(BaseModel): id = PrimaryKeyField(primary_key=True, unique=True) firstname = CharField() lastname = CharField() username = CharField(unique=True) telephone = IntegerField(null=True, default=None) # Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ Π½ΠΎΠ²ΠΎΠ³ΠΎ ΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΠ΅Π»Ρ: user = User.create(firstname='ΠΠΌΡ', lastname='Π€Π°ΠΌΠΈΠ»ΠΈΡ', username='ΠΠΈΠΊΠ½Π΅ΠΉΠΌ') # ΠΠΎΠΏΡΡΡΠΈΠΌ ΠΎΠ½ ΠΏΡΠΈΡΠ»Π°Π» Π½ΠΎΠΌΠ΅Ρ user.telephone = 00000000000 user.save() user.update()
I advise you to use ORM right away as they greatly simplify life and speed up development.
- Thanks, and if he sends the number through the button? - Yuri Popov
- And the difference? You just get this number, and how this question to how your bot works. I did not quite understand what it means "through the button" - MrSmitix 3:42 pm
|