These are chat archives for django/django

Nov 2016
Ismael Venegas Castelló
Nov 16 2016 01:34 UTC
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
Nov 16 2016 02:38 UTC
cant you just build a method named custom_id and have it return + 7000
Nov 16 2016 06:09 UTC
@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ó
Nov 16 2016 06:58 UTC
@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
Nov 16 2016 07:37 UTC
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
Nov 16 2016 07:49 UTC
@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
def custom_id(self):
    return + 7000
Robert Binneman
Nov 16 2016 07:54 UTC
@dreinhold before the record is saved adding to 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
Nov 16 2016 08:03 UTC
@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 else: returning "somthing" else None or 0
Miracle Ayodele
Nov 16 2016 10:19 UTC
@mheppner that's true, worked fyn on my shell
not yet on my app
Jatto Abdulqahhar
Nov 16 2016 22:04 UTC
hi , please ppl, i need to add a newsletter and subscription functionality to my django app, please how do i go about it?