django-views

Django how to add data to Object from queryset

六月ゝ 毕业季﹏ 提交于 2019-12-25 17:08:53
问题 I would like show list of clients and show tags assigned to them but I have problem because I have my tags in other table and I dont know how to connect data together. Clients can have couple of tags or none of that. Which way is correct to do this? Can you advice me something? I need one variable with tags separated comma or objects with tags which I can use in template engine. Views.py: @user_passes_test(lambda u: u.is_staff, login_url='/account/login/') def client_list(request): dict = {}

Django how to add data to Object from queryset

余生长醉 提交于 2019-12-25 17:07:38
问题 I would like show list of clients and show tags assigned to them but I have problem because I have my tags in other table and I dont know how to connect data together. Clients can have couple of tags or none of that. Which way is correct to do this? Can you advice me something? I need one variable with tags separated comma or objects with tags which I can use in template engine. Views.py: @user_passes_test(lambda u: u.is_staff, login_url='/account/login/') def client_list(request): dict = {}

Set a models user field to the current logged in user before saving its django ModelForm

主宰稳场 提交于 2019-12-25 12:45:14
问题 i have a model form as so below class JobForm(ModelForm): class Meta: model = Job exclude = ('date_added', 'date_modified','owner','status','tags','slug','winning_tech','completiondate') The owner field is a foreignKey linked to the Django User model and it's excluded from being rendered in the form. I am trying to set the owner field to the current logged in user before i save the form. My save function is contained in the following code. def createJob(request): bix_user=getBixUser(request

Creating a User Profile page using OneToOne field with User Model

∥☆過路亽.° 提交于 2019-12-25 08:47:24
问题 I'm currently using Django all-auth, and it has a /accounts/profile page which I want to create/populate with a form which updates user information. I have a Teacher field, which extends the User Model using OneToOne field. models.py class Teacher(models.Model): user = models.OneToOneField(User, on_delete=models.PROTECT, related_name='Teacher') bio = models.TextField(max_length=500, blank=True) availability = models.BooleanField(default=False) teacher_logo = models.FileField() This teacher

Hyphens in SlugField

自闭症网瘾萝莉.ら 提交于 2019-12-25 08:16:04
问题 There is a strange error when i open a URL with hyphens in the slug, though SlugField supports hyphens in it as indicated in documentation. So, this is the error: Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8003/dumpster-rental-prices Using the URLconf defined in dumpster.urls, Django tried these URL patterns, in this order: ^admin/ ^(?P<slug>\w+)/$ The current URL, dumpster-rental-prices, didn't match any of these. If i change the slug of the article to dumpster

How to transfer edit method of an ID to a button/links in Django?

可紊 提交于 2019-12-25 07:35:30
问题 This is the code in my ulrs.py url(r'^viewguides/detail/(?P<id>\d+)/edit/$', views.post_update, name='update'), Now I want to make it look like this: <a href="/detail/(?P<id>\d+)/edit" class="btn btn-default btn-lg" style="background-color: transparent;"><font color="Orange"> EDIT </font></a><hr> So that I can edit the certain ID that I want to. But it gives me an error. How do you do it? or is there any other way? I'm new to Django. 回答1: I just asked my colleagues who have some experience in

django HttpResponseForbidden not working

落花浮王杯 提交于 2019-12-25 07:28:14
问题 I'm excepting this code at is_send_permitted_interceptor if true to stop processing and redirect to forbidden. However, it does not, instead it returns the HttpResponseForbidden object in the function. How do I actually get HttpResponseForbidden() to run in this context. @login_required def process_all(request): #If we had a POST then get the request post values. if request.method == 'POST': batches = Batch.objects.for_user_pending(request.user) # Will redirect/cancel request if user does not

Create, Update and Delete in Django

依然范特西╮ 提交于 2019-12-25 07:27:03
问题 I am only creating entries for some fields in my models.py at the moment. Now I want to add Delete and Update functions to my Application. Let's take this Model for example: class todoList(models.Model): trainee = models.ForeignKey(trainee, verbose_name = "Azubi", blank = True) todoLearningObjective = models.ManyToManyField(learningObjective, verbose_name = "Lernziel", blank = True, null = True) tasks = models.TextField(verbose_name = 'Aufgaben') levyDate = models.DateField(verbose_name =

'__proxy__' object has no attribute 'get' in CreateView

流过昼夜 提交于 2019-12-25 07:14:05
问题 So I'm thinking that this is not the right way to do things, but I am trying to learn django and I am trying some things out. I am trying to set a foreign key for my Formula model, by hardcoding in an instance of maker . Models: class Cooker(models.Model): name = models.CharField(max_length=20, name="name") background = models.CharField(max_length=500, name="background") class Formula(models.Model): food = models.CharField(max_length=200, name="food") maker = models.ForeignKey(Cooker, related

Django - how to normalize database?

╄→гoц情女王★ 提交于 2019-12-25 06:07:01
问题 I keep asking people how I should organize my model, and they keep telling me to normalize the database. Can someone show me an example of a normalized Django model? 回答1: Normalisation is not a Django or even Python concept - it is a wider approach to designing a relational database schema such that you remove duplication and eliminate redundancy. In django this means that rather than have one model, you might have multiple smaller models, which represent the relationship between database