passing a parameter through CreateView to a be an initial value in a form
Hey Patric, Have a look at stackoverflow. https://stackoverflow.com/a/60273100/7063031 I used form_valid in the createview to get the form instance field, passed the pk through the URL to the template, then used get_context in the view so the template can get the pk from the URL. You’ll understand better when you use it and play around with it. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e34e9ef6-9af8-4c6f-8bbf-29f64342c880%40googlegroups.com.
Re: [ANN] copernic v0.0.0
On Monday, February 17, 2020 at 11:13:38 PM UTC+1, Amirouche Boubekki wrote: > > I am very pleased to announce that I will work on porting my work on a > versioned database (read: scalable wikidata) to Python and Django. > > If you want to know more and follow the development watch this: > https://github.com/amirouche/copernic > I put together the basic building blocks: generic tuple store and the versioned generic tuple store. The tests pass, however the absence of proof, is not the proof of the absence, so there might be bugs. Anyway, I added two issues: - How to convert wordnet rdf into the format that will be accepted by copernic: https://github.com/amirouche/copernic/issues/11 - Another one about more about how the versioned and change request happen: https://github.com/amirouche/copernic/issues/10 It is still no possible to add changes from the web ui, but here is some screenshot: https://functional.cafe/@zig/103686859595640820 This project has the power the change the "Quatery industry" also known as the knowledge industry. The gist of the idea I want to demonstrate is how to apply the pull-request mechanic on any structured data. That idea, is applied directly to the creation and maintenance of a knowledge base, but it could be applied on most or any B2B or B2C products. The installation on at least on ubuntu 18.04, is straight forward, follow the instructions at: https://www.foundationdb.org/download/#ubuntu Then pip install -r requirements.txt And the rest is usual django stuff. I recommend you read nstore.py and vnstore.py. The UI is defined in frontend app. Happy hacking! -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9ef0df90-daf8-4107-884e-d021c7fb6777%40googlegroups.com.
passing a parameter through CreateView to a be an initial value in a form
Hello I am trying to pass a value from a link into CreateView and use that value as an inital value in a form. I am not having much success and am not sure that I am doing this correctly. Here is what I have so far: Link: Circuit Ref: {{ record.id1 }} urls.py path('addXC//', views.addXC.as_view(), name='addXC'), views.py class addXC(CreateView): model = Xcinventorytable fields = ['circuitref', 'circuitid', 'vendor', 'legacy', 'address', 'city', 'state', 'ciopsticket', 'notes'] success_url="/thanks/xcadded/" def get_form_kwargs(self): kwargs=super(addXC, self).get_form_kwargs() kwargs.update({'circuitref': circuitref}) return kwargs forms.py class XcinventorytableForm(ModelForm): class Meta: model = Xcinventorytable widgets = {'notes': forms.TextInput(attrs={'size':200, 'rows':2})} help_texts = {'Circuitref': ('Enter the circuitref listed at the top of the last screen')} fields = '__all__' def __init__(self, *args, **kwargs): circuitref = kwargs.pop('circuitref') super(XcinventoryForm, self).__init__(*args, **kwargs) self.fields['circuitref'].initial = circuitref Any help or suggestions are appreciated -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/fd729e92-6256-4c3a-84df-79250794d6f6%40googlegroups.com.
Re: Django queryset result and mysql query are wrong after updating from 3.0.2 to 3.0.3
بتاريخ الأربعاء، 19 فبراير، 2020 10:51:53 م UTC+3، كتب Ricardo H: > Hi Simon, > > > It was ok on 2.2.6, only on 3.0.3 it fails. > > > I use BigIntegerField because I use it for some calculations after that, but > even if I try with DurationField it doens't assert right. > > > Definitely must be caused by this patch, if I can't find another solution, > where and how should I report this ?. > > > Thanks. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1d4386ce-fb0e-4dc5-ae42-3636d9168eed%40googlegroups.com.
Re: Django queryset result and mysql query are wrong after updating from 3.0.2 to 3.0.3
Hello Ricardo, I suggest you follow these docs to submit your bug report and link to this thread. https://docs.djangoproject.com/en/3.0/internals/contributing/bugs-and-features/#reporting-bugs I'd mention that the issue is also present if you use `output_field=DurationField` as BigIntegerField was likely only working by change. Cheers, Simon Le mercredi 19 février 2020 14:51:53 UTC-5, Ricardo H a écrit : > > Hi Simon, > > It was ok on 2.2.6, only on 3.0.3 it fails. > > I use BigIntegerField because I use it for some calculations after that, > but even if I try with DurationField it doens't assert right. > > Definitely must be caused by this patch, if I can't find another solution, > where and how should I report this ?. > > Thanks. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0ce21876-4be1-4096-8537-c9d76894dd84%40googlegroups.com.
Re: Re: Re: I am filling up the form but my filled out items are not rendering into database and also the session is not working
How can I do ImageField and FileField in crispy forms On Thu, 20 Feb, 2020, 12:53 AM , wrote: > > > Yaa did that still facing issue > > > > *From: *onlinejudge95 > *Sent: *Thursday, February 20, 2020 12:32 AM > *To: *django-users@googlegroups.com > *Subject: *Re: Re: I am filling up the form but my filled out items are > not rendering into database and also the session is not working > > > > The template file > > > > > > <*form **method**="post" **novalidate*> > > No action attribute defined here. Where do you expect the data to be sent? > > > {% csrf_token %} > > <*div **class**="form-group col-md-4 mb-0"*> > {{ form.name|as_crispy_field }} > > <*div **class**="form-group col-md-4 mb-0"*> > {{ form.email|as_crispy_field }} > > <*div **class**="form-group col-md-4 mb-0"*> > {{ form.link_sent|as_crispy_field }} > > <*button **type**="submit" **class**="btn btn-primary"*>Start > <*button **type**="submit" **class**="btn btn-primary"*>Save > > > {% endblock %} > > > > > > *From: *Farai M > *Sent: *Wednesday, February 19, 2020 11:19 PM > *To: *django-users@googlegroups.com > *Subject: *Re: I am filling up the form but my filled out items are not > rendering into database and also the session is not working > > > > The session must be activated in the settings file check that it should > work smoothly. > > On the insert can u share the template file mostly .It is to do with post > requests not reaching back end. You can try to print the post request > before your save to model to see if all inputs are coming through.If it's > not that try get create to see if it's an problem with duplicates. > > > > > > > > > > > > > > *views.py from *django.views.generic *import *FormView, TemplateView > *from *django.shortcuts *import *render,redirect > *from *.models *import > *modelstep1,modelstep2,modelstep3,modelstep4,modelstep5,modelstep6,modelstep7,modelstep8,modelstep9,modelstep10 > *from *.forms *import > *FormStep1,FormStep2,FormStep3,FormStep4,FormStep5,FormStep6,FormStep7,FormStep8,FormStep9,FormStep10 > > *def *FormStep1View(request): > forms = FormStep1() > *return *render(request, *'form_1.html'*, context={*'form'*: forms}) > > > *def *addForm1(request): > form = FormStep1(request.POST) > *if *form.is_valid(): > u=modelstep1() > u.name = form.cleaned_data[*'name'*] > u.email = form.cleaned_data[*'email'*] > u.link_sent = form.cleaned_data[*'link_sent'*] > u.title = request.POST.get(*'name'*) > u.content = request.POST.get(*'email'*) > u.content = request.POST.get(*'link_sent'*) > u.save() > request.session[*'name'*] = u.name > request.session[*'email'*] = u.email > request.session[*'link_sent'*] =u.link_sent > *return *redirect(*'/form/2/'*,context={*'form'*: form}) > > > > *def *FormStep2View(request): > forms = FormStep2() > *return *render(request, *'form_2.html'*, context={*'form'*: forms}) > *def *addForm2(request): > form = FormStep2(request.POST) > *if *form.is_valid(): > v=modelstep2() > v.country=form.cleaned_data[*'country'*] > v.city=form.cleaned_data[*'city'*] > v.year_of_birth=form.cleaned_data[*'year_of_birth'*] > v.current_grade=form.cleaned_data[*'current_grade'*] > v.university=form.cleaned_data[*' university'*] > v.school=form.cleaned_data[*'school'*] > v.native_language=form.cleaned_data[*'native_language'*] > v.phone_number = form.cleaned_data[*'phone_number'*] > v.email_business=form.cleaned_data[*'email_business'*] > v.social_media=form.cleaned_data[*'social_media'*] > > request.session[*'country'*] = v.country > request.session[*'city'*] = v.city > request.session[*'year_of_birth'*] = v.year_of_birth > request.session[*'current_grade'*] = v.current_grade > request.session[*'university'*] = v.university > request.session[*'school'*] = v.school > request.session[*'native_language'*] = v.native_language > request.session[*'phone_number'*] = v.phone_number > request.session[*'email_business'*] = v.email_business > request.session[*'social_media'*]= v.social_media > *return *redirect(request, *'/form/3/'*, > context={*'form'*:form}) > > > *def *FormStep3View(request): > forms = FormStep3() > *return *render(request, *'form_3.html'*, context={*'form'*: forms}) > *def *addForm3(request): > form = FormStep3(request.POST) > *if *form.is_valid(): >x=modelstep3() >x.internship_idea = form.cleaned_data[*'internship_idea'*] >x.startup_business = form.cleaned_data[*'startup_business'*] >x.goals =
Re: Django queryset result and mysql query are wrong after updating from 3.0.2 to 3.0.3
Hi Simon, It was ok on 2.2.6, only on 3.0.3 it fails. I use BigIntegerField because I use it for some calculations after that, but even if I try with DurationField it doens't assert right. Definitely must be caused by this patch, if I can't find another solution, where and how should I report this ?. Thanks. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0c714166-b3ec-4b58-b574-0effc0fd7f37%40googlegroups.com.
Django: ManyToManyField appears as empty on my template
I'm having an issue displaying a ManyToManyField in a character profile template using Django. The template has to show an avatar, alongside some information about the character, including a list of guilds this character had joined. But, when I try to display that list, it appears as if it is empty. I had a look into my site administration page, and that information is there, so I have confirmation that the data can be displayed in my template. I just don't know how. How could I handle that? These are my models: """ Modelos de la aplicación de personajes """ from django.db import models class Guild(models.Model): """ Modelo del clan """ guild_name = models.CharField(max_length=25) rank = models.PositiveSmallIntegerField() def __str__(self): return self.guild_name class Character(models.Model): """ Modelo del personaje """ character_name = models.CharField(max_length=25) level = models.PositiveSmallIntegerField() race = models.CharField(max_length=25) gender = models.CharField(max_length=25) job = models.CharField(max_length=25) avatar = models.ImageField(upload_to='', blank=True) character_guilds = models.ManyToManyField(Guild, blank=True) def __str__(self): return self.character_name+': '+self.race+' '+self.job+' level '+str (self.level)+'. ' My view.py file: def characterprofile(request, pk): """ Método para mostrar el perfil de un personaje """ template = '../templates/character/characterProfile.html' profile = Character.objects.get(pk=pk) guilds = profile.character_guilds.all() context = { 'profile': profile, 'guilds': guilds } return render (request, template, context) And my template.html: {% extends 'base.html' %} {% block content %} {{ profile.character_name }}'s profile Return {% if profile.avatar %} {% else %} There is no avatar to display here. {% endif %} Information Name: {{ profile.character_name }} Level: {{ profile.level }} Race: {{ profile.race }} Gender: {{ profile.gender }} Job: {{ profile.job }} Guilds: {% for g in guilds %} {{ g }} {%endfor%} Copyright© 2020 {% endblock %} Many thanks in advance! -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e8ede78e-a01a-4bcf-8895-005af4fd8a60%40googlegroups.com.
Re: How to store a boolean expression (parse tree) in a model?
Could you simply make the connector field nullable to express that? Simon Le mercredi 19 février 2020 12:15:32 UTC-5, test a écrit : > > thanks, do you know how i can create custom leaf nodes when using MPTT or > treebeard? > > My parent nodes should have connector types such as AND/OR but the child > should not > > > On Tuesday, February 18, 2020 at 11:30:40 PM UTC-5, Simon Charette wrote: >> >> I suggest you have a look at the "Trees and Graph" section of the >> Django Packages website[0]. I've personally used MPTT and Treebeard >> in the past without too much trouble. >> >> You could also a field able to store composite data structures >> such as JSONField or even a dedicated PostgreSQL type[1] to efficiently >> store >> such data. >> >> Cheers, >> Simon >> >> [0] https://djangopackages.org/grids/g/trees-and-graphs/ >> [1] https://www.postgresql.org/docs/current/sql-createtype.html >> >> Le mardi 18 février 2020 18:13:39 UTC-5, test a écrit : >>> >>> Let's say I have: >>> >>> Calculator #1: >>> Expression: (True AND False) AND (True OR False) >>> >>> This expression should be a child of some calculator. >>> >>> class Calculator(models.Model): >>> name = ... >>> >>> class Expression(models.Model): >>> parent = models.ForeignKey(Calculator) >>> >>> boolean = AND or OR >>> >>> sub_exp1 = models.ForeignKey(Expression) >>> sub_exp2 = models.ForeignKey(Expression) >>> >>> >>> When I query all the expressions for the Calculator #1, I should get all >>> the subexpressions. >>> >>> 1 AND 2 5 >>> 2 AND 3 4 >>> 3 leaf node of True >>> 4 lead node of False >>> 5 OR 6 7 >>> 6 leaf node of True >>> 7 leaf node of False >>> >>> From this, I can quickly apply my parse tree. >>> >>> How would I display the base case/leaf nodes in my model? Also, is there >>> a better way? >>> >>> Thanks, I would really appreciate any help >>> >> -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1b1c4b6e-71e7-4613-854c-b96d0028f28b%40googlegroups.com.
Re: Django queryset result and mysql query are wrong after updating from 3.0.2 to 3.0.3
Hello Ricardo, This could be a regression caused by a patch addressing a regression in 3.0.3[0]. Did you also notice this behaviour on Django 2.2.x or was this project started from Django 3.0? >From what I can see though I find it strange that the ExpressionWrapper of end_total_time have an output_field of BigIntegerField instead of DurationField. That could be the origin of your issue. Cheers, Simon [0] https://github.com/django/django/commit/02cda09b13e677db01863fa0a7112dba631b9c5c Le mercredi 19 février 2020 13:08:57 UTC-5, Ricardo H a écrit : > > Hello, after I updated django from 3.0.2 to 3.0.3 the result of the > following code has changed when using a MySQL database. It produces a wrong > sql query and also the wrong result for "*end_total_time"* attribute. > Is this a bug ? also is there any other way to get the wright result using > 3.0.3 ? > > Thank you. > > *models.py* > from datetime import datetime > import pytz > > > from django.db import models > from django.db.models.functions import Cast > > > class PhaseQueryset(models.QuerySet): > > > def with_duration(self,): > base_date = datetime(2000, 1, 3, 0, tzinfo=pytz.utc) > > > # When I use base_date to do the end_total_time math in 3.0.3 > together > # with ended_at annotated, it creates a wrong query > qs = self.annotate( > ended_at=models.Case( > models.When( > models.Q(type='TYPEONE'), > then=models.functions.Now() > ), > default=models.F('started_at'), > output_field=models.DateTimeField(), > ), > base_date=models.functions.Cast( > models.Value(base_date), > output_field=models.DateTimeField() > ), > end_total_time=models.ExpressionWrapper( > models.F('ended_at') - models.F('base_date'), > output_field=models.fields.BigIntegerField() > ) > ) > > > return qs > > > # Create your models here. > class Phase(models.Model): > objects = PhaseQueryset().as_manager() > started_at = models.DateTimeField() > type = models.CharField(max_length=40) > > > > *tests.py* > from datetime import datetime, timedelta > import pytz > > > from django.test import TestCase > from daterror.models import Phase > # Create your tests here. > > > class TestDateProblem(TestCase): > > > def setUp(self,): > past = datetime.now(tz=pytz.UTC) - timedelta(days=30) > Phase.objects.create(started_at=past, type='TYPEONE') > past = datetime.now(tz=pytz.UTC) - timedelta(days=33) > Phase.objects.create(started_at=past, type='TYPETWO') > past = datetime.now(tz=pytz.UTC) - timedelta(days=34) > Phase.objects.create(started_at=past, type='TYPETHREE') > > > > > def test_timedifference_not_none(self,): > phases = Phase.objects.all().with_duration() > print(phases[0].end_total_time) > print(phases[1].end_total_time) > print(phases[2].end_total_time) > self.assertNotEqual(None, phases[0].end_total_time) > self.assertNotEqual(None, phases[1].end_total_time) > self.assertNotEqual(None, phases[2].end_total_time) > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4542b03e-797a-4e06-99c2-5ca77ccd4aec%40googlegroups.com.
RE: Re: Re: I am filling up the form but my filled out items are not rendering into database and also the session is not working
Yaa did that still facing issue From: onlinejudge95Sent: Thursday, February 20, 2020 12:32 AMTo: django-users@googlegroups.comSubject: Re: Re: I am filling up the form but my filled out items are not rendering into database and also the session is not working The template file