django-models

How to model tournaments database into a SQL in django

对着背影说爱祢 提交于 2020-01-06 06:38:17
问题 I want to model a tournament database to store data of online games My question is: How to create a model in relationship database to store all this types of tournaments? (such as, league of legends tournament, dota 2 tournament) For example, a tournament can have 8 teams or 5 teams. This is the sketch I created in my mind. What things do you suggest (especially I need help with relationships of tables). Also how to keep team 1 and team 2 in the match table (such as, scores, winner, loser) i

Assign Foreign Key Value after creating ( Logged In User )

喜你入骨 提交于 2020-01-06 06:32:09
问题 I have a createview using CBV class StudentCreate(LoginRequiredMixin, CreateView): login_url = '/signin/' model = Student fields = ['first_name', 'last_name' ] success_url = '/dashboard/' Respective models.py class Class_teacher(models.Model): first_name = models.CharField(max_length=200) last_name = models.CharField(max_length=200) standard = models.IntegerField() division = models.CharField(max_length=1) subject = models.CharField(max_length=200) email = models.CharField(max_length=30)

Django form not saving inputs- refreshes upon submission

两盒软妹~` 提交于 2020-01-06 06:04:27
问题 I am trying to create a website with two dropdown menus: Department and Course Number. The data for the dropdown menus comes from the "courses" table of my SQL database. Right now my website initializes properly and shows the correct options in the dropdown menus. However, when the user selects an option within the dropdown menus and submits their choices, the website reloads as a blank slate so their selections are not being saved or processed. The error lies somewhere in the CourseForm form

IntegrityError while saving a new item to the postgresql db in django?

北城以北 提交于 2020-01-06 05:05:07
问题 Django saves the data but eventually raises an IntegrityError. If there is an error, why it is saving that data? And I'm sure that the uniqueness property is not violated on that data. What is going on? Why is that error occurs? and how can I solve that? 回答1: Most likely your model has a field which doesn't allow null value and you are trying to add object without any value for that field. If you can Edit your post and add more details (like model & traceback) then you can expect better

Django model pre_save Validation in Admin

半城伤御伤魂 提交于 2020-01-06 04:52:11
问题 Following is my model: class Product(models.Model): product_title = models.CharField(max_length=100, null=False, verbose_name='Product title') product_description = models.TextField(max_length=250, verbose_name='Product description') product_qty = models.IntegerField(verbose_name='Quantity') product_mrp = models.FloatField(verbose_name='Maximum retail price') product_offer_price = models.FloatField(verbose_name='Selling price') def validate_produce_offer_price(sender, instance, **kwargs): if

Passing information between web pages in Django

蓝咒 提交于 2020-01-06 04:15:47
问题 I have an Image Gallery System where I'm building a feature to edit the attributes of an uploaded image. @login_required def edit(request): if request.method == 'POST': ZSN = request.POST['ZSN'] ZSN = 'images/' + ZSN + '.' image = Images.objects.filter(file__startswith=ZSN) if image: return HttpResponseRedirect('/home/photo-edit', {'image':image}) else: return HttpResponse("Invalid ZSN.") else: return render(request, 'cms/edit.html') This is my edit method in views.py . Notice that I am

how to increase the range of years to show up in Django templates?

不羁岁月 提交于 2020-01-06 04:12:07
问题 In the signUp form I am creating, I am pre-populating the date-of-birth field to "yesterday". But the scroll down menu for year is limited to 9 years. how can I increase the number of years to show up. It must not be limited. I have attached the image. you can see that there is an option to choose only among those nine years. Any ideas how to fix this? signups/forms.py: from django import forms from signups.models import SignUp import datetime from django.forms.extras.widgets import

django multivaluefield & multiwidget - make one optional

ⅰ亾dé卋堺 提交于 2020-01-06 03:13:08
问题 This is related to an earlier question of mine. I want to have a MultiValueField which contains a Choice and TextInput widget. If the user selects "OTHER" from the Choice, then the value of the TextInput should be saved. Otherwise, the value of the Choice should be saved. So far I have the following code: custom_choices = [("one","one"),("two","two"),("OTHER","OTHER")] class MyMultiWidget(forms.MultiWidget): def __init__(self,*args,**kwargs): widgets = ( forms.Select(choices=custom_choices),

python django - page not found error (404)- static error

这一生的挚爱 提交于 2020-01-06 03:11:47
问题 I somehow got the application running on django (new to python and django) and although the page loads the default URL (127.0.0.1:8000) but it does load the css files. It produces following error css files are directly accessed. Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/static/css/bootstrap.min.css 'css\bootstrap.min.css' could not be found You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django

GitHub issue ids start at 1 for each repository, how can I replicate this in Django?

筅森魡賤 提交于 2020-01-06 02:50:08
问题 On Github, the first issue for each repository has id 1, despite there being many other issues on GitHub. https://github.com/johndoe/foo/issues/1 How can I accomplish this in Django, so that a model has an id that only increments in relation to a model it is related to? 回答1: You can simply create an extra unique field on the model, here's an example class MyModel(models.Model): user = models.ForeignKey(User) internal_id = models.CharField(verbose_name=_(u"Internal ID"), max_length=7)