These are chat archives for django/django

16th
Nov 2016
Ismael Venegas Castelló
@SalchiPapa
Nov 16 2016 01:34
Hello!
How can I make somethin like this:
    id = models.AutoField(primary_key = True)
    custom_id = models.CharField(max_length = 20, default = 7000 + int(id.value_to_string()), editable = False)
I need a custom id starting at 7000 that is equal to 7000 + id as the default value
ie, I want to emulate another auto increment field in order to display it to the user
Dylan Reinhold
@dreinhold
Nov 16 2016 02:38
cant you just build a method named custom_id and have it return self.id + 7000
sukianto
@sukianto
Nov 16 2016 06:09
@RadoRado sorry nvm, and thanks :)
can u help me with logic for connecting one account to another account
or maybe some article to do that on django
Ismael Venegas Castelló
@SalchiPapa
Nov 16 2016 06:58
@dreinhold I'm on my cellphone right now. But I tried that and it was a ValueError or TypeError because id's type is not an integer, but an AutoField. I noticed it's value_to_string method, so I thought that would work. But I can't check what was the exact error for thar now. I think I'm confused how Models and Forms are used! :P
Stephen James
@StephenOrJames
Nov 16 2016 07:37
If I'm not mistaken, AutoFields are IntegerFields, which are integers, so unless id wasn't set, it should work. Also, if you use it as a property, you get to call it without parenthesis :smile:
Dylan Reinhold
@dreinhold
Nov 16 2016 07:49
@Ismael-VC if I had to guess you were missing the self. in front of id that would give you a type error. and as @StephenOrJames says make it a \@property
@property
def custom_id(self):
    return self.id + 7000
Robert Binneman
@RobertBinneman
Nov 16 2016 07:54
@dreinhold before the record is saved adding to self.id will cause a TypeError
to generate this you would need to override the save method to save the record, then create the custom id and save it again
Dylan Reinhold
@dreinhold
Nov 16 2016 08:03
@oceanbird yeah if you read it before it's saved true. Depending on the usecase might be as simple as wrapping it in an if self.id: else: returning "somthing" else None or 0
Miracle Ayodele
@iammiracle
Nov 16 2016 10:19
@mheppner that's true, worked fyn on my shell
not yet on my app
Jatto Abdulqahhar
@jattoabdul
Nov 16 2016 22:04
hi , please ppl, i need to add a newsletter and subscription functionality to my django app, please how do i go about it?