django

How can I allow user to submit a form

How can I allow user to submit a form Question: When I try to submit Table model to the database using create_table view, it throws me an error: NOT NULL constraint failed: audioApp_table.user_id after I do my own research I found out it was because I didn’t add user to the form, so I try …

Total answers: 1

How to avoid IntegrityError issue with update_or_create?

How to avoid IntegrityError issue with update_or_create? Question: I would appreciate it if someone could explain why I’m having IntegrityError exception being thrown here, and how to avoid it. When an object already exists, isn’t the update_or_create method supposed to update it ? models.py class OHLCV(TimestampedModel): market = models.ForeignKey(Market, on_delete=models.CASCADE, related_name=’candles’, null=True) index = models.ForeignKey(Index, …

Total answers: 1

Auto pre-fill form Django

Auto pre-fill form Django Question: How to pre-fill form fields in Django. What would be the pre-filled data from the User class when forming the order form. The result need like this: my view def order_create(request): cart = Cart(request) user = request.user if request.user.is_authenticated: if request.method == ‘POST’: form = OrderCreateForm(request.POST) if form.is_valid(): order = …

Total answers: 1

Bootstrap’s cards. How to shorten the words in card with … . Django & CSS

Bootstrap’s cards. How to shorten the words in card with … . Django & CSS Question: I am using the Bootstrap’s card to display my journals. It looks like this: Journal List However, when I insert a lot of word, the card size will be veryyyy long. Journal List With really long essay How to …

Total answers: 2

How to create clickable links for foreign keys in Django admin panel?

How to create clickable links for foreign keys in Django admin panel? Question: How to make foreign keys clickable in Django admin list view to open related detail admin page? Currently, Django admin displays foreign keys as plain text in the list view. Is there a way to make these foreign keys clickable links that …

Total answers: 1

Accessing Calls to Mocked Class functions

Accessing Calls to Mocked Class functions Question: I have written a custom class to mock a general API client in a codebase so that I can centrally and easily mock all of the class methods for unit testing. This is working great so far, however I am looking for a way to track individual calls …

Total answers: 1

Django automated runserver and functional test

Django automated runserver and functional test Question: Im trying to use invoke module to automate my django functional tests, but I realised as the runserver command is rolling on my script waits until its finished to run the next command from invoke import task @task def runserver(c): c.run(‘python manage.py runserver’) @task def test(c): c.run(‘python functional_test.py’) …

Total answers: 1

How can I use a property inside another property? Django

How can I use a property inside another property? Django Question: I have the following model with three properties to know the consumption according to the reading: class ConsElect(models.Model): pgd = models.ForeignKey(TipoPGD, on_delete=models.CASCADE, related_name=’consumoelect’) data= models.DateField(default=datetime.now) read_morning = models.IntegerField(default=0) read_day = mod def get_rm(self): c_m = list(ConsElect.objects.filter(data__gt=self.data).values(‘read_morning’)[0:1]) return ((c_m[0][‘read_morning ‘] – self.read_morning )) cons_m= property(get_rm) …

Total answers: 1

How to add another dictionary entry in a nested python dictionary

How to add another dictionary entry in a nested python dictionary Question: I would like to make a dictionary in the dictionary. I have this code dictionary = {} for g in genre: total = 0 products = Product.objects.filter(genre=g) for product in products: total += product.popularity dictionary[g.category] = {g.name: total} I would like it to …

Total answers: 4