django-admin

How to get created object in CreateView

断了今生、忘了曾经 提交于 2020-08-24 11:16:30
问题 Here I am using CreateView to create item and after that i am redirecting user to update other fields of currently created object. Here my code: Views.py class DynamicCreate(CreateView): model = Dynamic form_class = DynamicForm template_name = 'book/dynamic_create.html' def form_valid(self, form): book = form.save(commit=False) book.user = User.objects.get(pk=(self.request.user.pk)) book.save() return reverse('book:dynamicupdate', args=(self.object.id)) Urls.py url(r'^book/create/$', views

How to set a random integer as the default value for a Django CharField?

*爱你&永不变心* 提交于 2020-08-24 05:57:46
问题 My models.py looks like this: import random random_string = str(random.randint(10000, 99999)) class Content(models.Model): ...... unique_url = models.CharField(default = random_string) When I add a content in admin, an integer in the range is generated and put into the charfield as its default value. From there, I can simple add more words to the charfield. However, the problem with my current set-up is that the integer remains the same every time I add a new article. I want to generate and

How to set a random integer as the default value for a Django CharField?

六月ゝ 毕业季﹏ 提交于 2020-08-24 05:56:30
问题 My models.py looks like this: import random random_string = str(random.randint(10000, 99999)) class Content(models.Model): ...... unique_url = models.CharField(default = random_string) When I add a content in admin, an integer in the range is generated and put into the charfield as its default value. From there, I can simple add more words to the charfield. However, the problem with my current set-up is that the integer remains the same every time I add a new article. I want to generate and