Re: Custom User

2020-03-06 Thread Antje Kazimiers
Hi Kushal,

Since the out-of-the box User model is coming from the auth module, you
can hardly extend this class. To store additional information for
different types of Users, you could create a custom UserProfile model,
which has a Foreign Key to the User model:


from django.db import models
...

class UserProfile(models.Model):
    class Meta:
    verbose_name_plural = "User Profiles"

    user = models.ForeignKey(User, related_name='user_profile', unique=True)
    user_type = models.CharField(max_length=1, choices=USER_TYPE,
default='h')

You could also write your own custom User Model with a user type field
and use that one instead of the built-in one:

https://docs.djangoproject.com/en/2.1/topics/auth/customizing/#substituting-a-custom-user-model


But what you describe almost sounds like you want to make use of the
permissions and groups, which are built into the django admin interface
as well, so I would read through this:

https://docs.djangoproject.com/en/3.0/topics/auth/default/#permissions-and-authorization


Antje

On 3/5/20 8:19 AM, Kushal Neupane wrote:
> I am trying to build a resturant management system. I made a super
> user. Now, i am trying to make cashier and finance users which must be
> assign by the super admin. Can i do 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/59fed919-bf3b-40aa-8cd8-00f6cf7335a9%40googlegroups.com
> .

-- 
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/31516228-9acd-5037-006e-56674405f582%40gmail.com.


Re: Django mail

2020-03-22 Thread Antje Kazimiers
Couldn't you also set up cron jobs to check for some conditions you have
to come up with, which are using the fields of your User model like
date_joined and check, if fields of your user profile are filled in with
respect to the created date of your profile?

I would start with writing some django commands to query those
conditions and send out the email using django send_mail. Those commands
you could then schedule with cron jobs.

https://docs.djangoproject.com/en/3.0/howto/custom-management-commands/
https://docs.djangoproject.com/en/3.0/topics/email/

Antje

On 3/22/20 12:02 PM, DHRUVA wrote:
> Hey thanks 
>
> The events would be like if they haven't verified their profile after
> signup then in 24 hours still not done after 3 days.So then the same
> with the profile build up if they have filled half then a Mail to
> complete.
>
> Thanks
>
> On Sun, 22 Mar, 2020, 4:23 PM Kasper Laudrup,  > wrote:
>
> Hi Mike,
>
> On 22/03/2020 11.01, DHRUVA wrote:
> > Thanks
> > But how to do scheduling of the mails automatically on the basis
> of the
> > events.
> >
>
> You might be able to handle this with Django signals:
>
> https://docs.djangoproject.com/en/3.0/topics/signals/
>
> But since you've mentioned you want events to be triggered based
> on some
> timer, you should probably look into Celery integration:
>
> 
> https://docs.celeryproject.org/en/latest/django/first-steps-with-django.html
>
> I don't have any personal experience with Celery, but I'm sure others
> here do and will be happy to help you with any issues you might have.
>
> Kind regards,
>
> Kasper Laudrup
>
> -- 
> 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/9fbe9f68-2296-3b6c-5ac8-952e1dde95fd%40stacktrace.dk.
>
> -- 
> 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/CANvoF%2B8G3uRCDUtjvzVJf0-3kaLeETj%2B00kJgJ4bJ2nvOh0c%3DQ%40mail.gmail.com
> .

-- 
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/84827027-1f55-8085-19e2-a0527ece790e%40gmail.com.


Re: Django Login Problem

2020-03-29 Thread Antje Kazimiers
Hi,

It sounds like you don't get an error message, so maybe your authenticate 
method in

def sign_in(request)

just returns a None user and you get redirected. I would find this method in 
your django installation, for me it's in the env folder but that depends on 
your setup:

./env/lib/python3.7/site-packages/django/contrib/auth/__init__.py

and debug into it or add some print statements to see why this is failing.

Antje

> On 29. Mar 2020, at 10:33, pratiksha jain  wrote:
> 
> I have problem in loging in after signing up. I have tried all the methods 
> that I can try, I want to know my errors.
> Thank you
> 
> -- 
> 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/f542af27-682f-4528-b1e8-70acfc6c8e1e%40googlegroups.com
>  
> .
> 

-- 
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/820B2E17-AB07-4F17-9117-88D1AD3B7ED4%40gmail.com.


Re: Issue with passing parameters in urls

2020-04-01 Thread Antje Kazimiers
Hi Aniket,

Your thread object in your template is actually a message since your
passing messages to context in your view.

but when you initialize messages you don't set a name attribute.

So I would double check your Message model if it has a name attribute.

btw your error message didn't display for me.

Antje

On 3/30/20 4:50 PM, aniket kamthe wrote:
> Hey All, 
> I have been watching your youtube tutorials and have been stuck on an
> issue for a while now. Can you help me out pls - 
>
> I am trying to pass a parameter via a button in an HTML file and using
> that in the next link to access a specific set of entries from the
> database - 
>
> HTML File code - 
>
> {% for thread in object %}
> role="button">{{ thread.name }} Something  {% endfor %}
> URLs files code - 
> path('message//', views.message, name='message'),
> Views files code 
> def message(request, threadid):
>   if request.method == 'POST':
> print(request.POST.get('message'))
> m = messages(message=request.POST.get('message'), thread_id='00', 
> likes='00', Message_flags='00')
> m.save();
> if (request.method == 'POST') and ("like" in request.POST):
>   print("hi")
> data = messages.objects.all()
> context = {
>   'object': data
> }
> return render(request, 'mysite/message.html', context)
>   else:
> data = messages.objects.all()
> context = {
>   'object': data
> }
> return render(request, 'mysite/message.html', context)
> But I get this error, idk how to resolve this one - 
>
> image.png
> Pls let me know If you are able to figure out the problem. 
> -- 
> 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/deae3154-4d36-438a-9669-5698d319ed27%40googlegroups.com
> .

-- 
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/879b4154-a801-9080-96a3-0f28e5e38ac1%40gmail.com.


Re: how to use django template language inside script html tag using django-jsRender

2020-04-03 Thread Antje Kazimiers
I think you can use some basic template language within a script block like
below. myData is a stringified json object, that worked for me.
antje


  {% if myData %}
var table_data = {{ myData|safe }};
  {% else %}
var table_data = null;
  {% endif %}



On Fri, Apr 3, 2020 at 4:00 PM Yacin Omar  wrote:

> As I know, there is no way to use Django template language inside
> Javascript block so I searched for a way how to do it, I found a Django app
> on github  called django-jsrender but unfortunately, there isn't enough
> documentation for this app and when I tried to use it I couldn't and this
> is my code:
>
> [image: Capture.PNG]
>
> --
> 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/a1c20606-bf66-4638-a006-be592a938c66%40googlegroups.com
> 
> .
>

-- 
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/CAN6tUh%3DQ4Ueh%2B%2BHA-2PwmYpv0MwLhc%3DFKMiDt9jz1GeKgiKiWA%40mail.gmail.com.


Re: Django - PrePopulate the Foreign Key on the web page, and use that id to save the model.

2020-04-12 Thread Antje Kazimiers
 Hi, I think in your view modulesView() you need to pass the project id to 
ModuleForm:

..
else :
form = ModuleForm(projectid)
..

and then you need to overwrite the constructor of ModuleForm by adding an 
__init__ function:

  def __init__(self, projectid=None, *args, **kwargs):
super(ModuleForm, self).__init__(*args, **kwargs)
if projectid is not None:
self.fields['project'] = forms.ModelChoiceField(
...
queryset=Project.objects.filter(id=projectid)
)

something like that. --Antje

On Sunday, April 12, 2020 at 8:14:51 AM UTC+2, Mayank Tripathi wrote:
>
> Hi All,
>
> I am facing an issue, to pre-populate the Foreign Key on the web page.
> Actually i have two models Projects and Modules. 
> To create a Module, one has to select the Project and go to Module page 
> for create it, but there the Project is not populated.
>
> Below are the details... Please guide me.
>
> *models.py*
> class Project(models.Model): 
> name = models.CharField(max_length = 200, null = True)
> startdate = models.DateTimeField()
>
> def __str__(self):
> return self.name
>
> class Modules(models.Model): 
> project = models.ForeignKey(Project, null = True, on_delete = 
> models.SET_NULL) 
> modulename = models.CharField(max_length = 200, null = True)
> modulestartdate = models.DateTimeField()
>
> def __str__(self):
> return self.modulename 
>
> *forms.py*
> class ProjectForm(forms.ModelForm):
> class Meta:
> model = Project
> fields = '__all__'
>
>
> class ModuleForm(forms.ModelForm): 
> class Meta: 
> model = Modules
> fields = '__all__'  
>
> *views.py*
> def projectView (request):
> if request.method == 'POST':
> form = ProjectForm(request.POST) 
> if form.is_valid():
> form.save(commit=True)
>
> return render(request, 'budget/projectForm.html', {'form': form})
>
> else :
> form = ProjectForm()
> return render(request, 'budget/projectForm.html', {'form': form})
>
>
> def modulesView (request, projectid):
> project = Project.objects.get(pk=projectid)
>  
> if request.method == 'POST':
> form = ModuleForm(request.POST) 
> if form.is_valid():
> form.save(commit=True)
>
> return render(request, 'example/modulesForm.html', {'form': form})
>
> else :
> form = ModuleForm(instance=project)
> return render(request, 'example/modulesForm.html', {'form': form})
>
> *urls.py*
> path('testproject/', views.projectView, name='projectView'),
> path('testprojectmodule//', views.modulesView, 
> name='modulesView'),
>
> in html forms for both Project and Modules... just using {{ form.as_table 
> }}.
>
> Now after createing the Project, i used the url as 
> http://127.0.0.1:8000/testprojectmodule/1/ 
> then my Project should get pre-populated... as reached using the project 
> id which is 1 in this case, but i am getting full drop-down. Refer attached 
> image.
> Either the Project should be pre-selected.. or can make it non-editable 
> either will work for me.
>
> Please 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/26744cb1-03e3-4189-a438-0b462013bb66%40googlegroups.com.


Re: Django - PrePopulate the Foreign Key on the web page, and use that id to save the model.

2020-04-13 Thread Antje Kazimiers
you're welcome, Mayank!

Adding initial to your ModelChoiceField definition should give you the
preselection.

  self.fields['project'] = forms.ModelChoiceField(
initial=projectid,
queryset=Project.objects.filter(id=projectid)
)

On Sun, Apr 12, 2020 at 10:58 PM _M_A_Y_A_N_K_ 
wrote:

> Cool, thanks Antje.
>
> Seems it is working now, the only thing is in Drop-down i will have the
> Project Name for which the URL is rest of the PRojects are removed from
> drop down.
> Now will work to have pre-selected. As of now it will default display as
> -- with only one required project name.
>
> Thanks & Regards,
> -
> Mayank Tripathi
> Mo. +1 615 962 2128
> "Do what you can, with what you have, where you are -by Theodore
> Roosevelt"
> https://datascience.foundation/datascienceawards
>
>
>
> On Sun, Apr 12, 2020 at 3:07 AM Antje Kazimiers 
> wrote:
>
>> Hi, I think in your view modulesView() you need to pass the project id to
>> ModuleForm:
>>
>> ..
>> else :
>> form = ModuleForm(projectid)
>> ..
>>
>> and then you need to overwrite the constructor of ModuleForm by adding an
>> __init__ function:
>>
>>   def __init__(self, projectid=None, *args, **kwargs):
>> super(ModuleForm, self).__init__(*args, **kwargs)
>> if projectid is not None:
>> self.fields['project'] = forms.ModelChoiceField(
>> ...
>> queryset=Project.objects.filter(id=projectid)
>> )
>>
>> something like that. --Antje
>>
>> On Sunday, April 12, 2020 at 8:14:51 AM UTC+2, Mayank Tripathi wrote:
>>>
>>> Hi All,
>>>
>>> I am facing an issue, to pre-populate the Foreign Key on the web page.
>>> Actually i have two models Projects and Modules.
>>> To create a Module, one has to select the Project and go to Module page
>>> for create it, but there the Project is not populated.
>>>
>>> Below are the details... Please guide me.
>>>
>>> *models.py*
>>> class Project(models.Model):
>>> name = models.CharField(max_length = 200, null = True)
>>> startdate = models.DateTimeField()
>>>
>>> def __str__(self):
>>> return self.name
>>>
>>> class Modules(models.Model):
>>> project = models.ForeignKey(Project, null = True, on_delete =
>>> models.SET_NULL)
>>> modulename = models.CharField(max_length = 200, null = True)
>>> modulestartdate = models.DateTimeField()
>>>
>>> def __str__(self):
>>> return self.modulename
>>>
>>> *forms.py*
>>> class ProjectForm(forms.ModelForm):
>>> class Meta:
>>> model = Project
>>> fields = '__all__'
>>>
>>>
>>> class ModuleForm(forms.ModelForm):
>>> class Meta:
>>> model = Modules
>>> fields = '__all__'
>>>
>>> *views.py*
>>> def projectView (request):
>>> if request.method == 'POST':
>>> form = ProjectForm(request.POST)
>>> if form.is_valid():
>>> form.save(commit=True)
>>>
>>> return render(request, 'budget/projectForm.html', {'form': form})
>>>
>>> else :
>>> form = ProjectForm()
>>> return render(request, 'budget/projectForm.html', {'form': form})
>>>
>>>
>>> def modulesView (request, projectid):
>>> project = Project.objects.get(pk=projectid)
>>>
>>> if request.method == 'POST':
>>> form = ModuleForm(request.POST)
>>> if form.is_valid():
>>> form.save(commit=True)
>>>
>>> return render(request, 'example/modulesForm.html', {'form': form})
>>>
>>> else :
>>> form = ModuleForm(instance=project)
>>> return render(request, 'example/modulesForm.html', {'form': form})
>>>
>>> *urls.py*
>>> path('testproject/', views.projectView, name='projectView'),
>>> path('testprojectmodule//', views.modulesView,
>>> name='modulesView'),
>>>
>>> in html forms for both Project and Modules... just using {{
>>> form.as_table }}.
>>>
>>> Now after createing the Project, i used the url as
>>> http://127.0.0.1:8000/testprojectmodule/1/
>>> then my Project should get pre-populated... as reached us

Re: Models as choices

2020-04-16 Thread Antje Kazimiers
with a Foreign Key field, one-to-many relationship:

https://docs.djangoproject.com/en/3.0/topics/db/examples/many_to_one/

Antje

On 4/16/20 6:52 AM, shreehari Vaasistha L wrote:
> how can i use model x values as choices for model y ?
>
> for eg:
> |
> classcountries(models.Model):
>  country =models.CharField(max_length=200)
>
>  def__str__(self):
>  returnself.country
>
> classUser(AbstractUser):
>  """User model."""
>
>  username =None
>  full_name =models.CharField(_("Full
> Name"),max_length=50,default="Full Name")
>  country_choices =models.CharField(choices=countries
> |
> -- 
> 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/683251c6-27ab-4454-90d6-532fdcc749ce%40googlegroups.com
> .

-- 
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/f6aeed6e-de34-f8f6-ce26-31151d4dee83%40gmail.com.


Re: Problem in polls app(ques text will not display)

2020-04-21 Thread Antje Kazimiers
It sounds like your database is empty. Did you check if there are any
Question records in your admin view? Under

127.0.0.1:8000/admin

You should see an entry for Questions and you can create question
records there.

Here they describe, how to create those records using the django
management shell:

https://docs.djangoproject.com/en/3.0/intro/tutorial02/#playing-with-the-api

I think if you have records in your database, the index view should list
them.

Antje

On 4/21/20 7:50 PM, Balkrishana Gaur wrote:
> Dear sir i am new to django. And following each and every step to create my 
> first app. Almost done. But at the time of polls question no text will 
> display while i use to run 127.0.0.1/8000/polls
> What can i do
>

-- 
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/d6459c76-f83f-b902-19aa-7e4bcdcbacfb%40gmail.com.


Re: The database backend does not accept 0 as a value for AutoField.

2020-04-26 Thread Antje Kazimiers
setting default=False is odd for any field other than a BooleanField. I
would take that out for the OneToOneField at least and see how things go.

Antje

On 4/26/20 4:19 PM, Mayur Bagul wrote:
> Hello guys,
>
> im stucked with this error mentioned in subject.
> below link redirect details about question.
>
> https://stackoverflow.com/q/61427882/11351226
>
> let me know how to get rid of this problem.
>
>
> Thanking You.
>
> -- 
> 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/cad442bf-e697-47c6-a0b4-3ce65bcef480%40googlegroups.com
> .

-- 
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/893f62fe-966e-d71b-8155-df9decf1786d%40gmail.com.


Re: The database backend does not accept 0 as a value for AutoField.

2020-04-26 Thread Antje Kazimiers
how about adding null=True and blank=True to the field?

On 4/26/20 6:38 PM, Mayur Bagul wrote:
> Hey thanks for your response i did so because initially at the time of
> migration it was asking for default value and i just putted false in
> rush. that filed user from User model returns username as string
> autofield so what shall i put as default their?
> i tried to put None for default value but while migrating it giving
> same error :-- 
>
> |
>  line 192,invalidate_autopk_value
>     raiseValueError('The database backend does not accept 0 as a '
> ValueError:Thedatabase backend does notaccept 0asa value forAutoField.
> |
>
> guys help me with this error .
>
>
> On Sunday, April 26, 2020 at 9:10:41 PM UTC+5:30, Antje Kazimiers wrote:
>
> setting default=False is odd for any field other than a
> BooleanField. I would take that out for the OneToOneField at least
> and see how things go.
>
> Antje
>
> On 4/26/20 4:19 PM, Mayur Bagul wrote:
>> Hello guys,
>>
>> im stucked with this error mentioned in subject.
>> below link redirect details about question.
>>
>> https://stackoverflow.com/q/61427882/11351226
>> <https://stackoverflow.com/q/61427882/11351226>
>>
>> let me know how to get rid of this problem.
>>
>>
>> Thanking You.
>>
>> -- 
>> 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...@googlegroups.com.
>> To view this discussion on the web visit
>> 
>> https://groups.google.com/d/msgid/django-users/cad442bf-e697-47c6-a0b4-3ce65bcef480%40googlegroups.com
>> 
>> <https://groups.google.com/d/msgid/django-users/cad442bf-e697-47c6-a0b4-3ce65bcef480%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
> -- 
> 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
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/7c34122c-0260-4a5b-8586-42c0037f8192%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/7c34122c-0260-4a5b-8586-42c0037f8192%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
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/5dd77724-3b33-ee13-41b0-19bbcc927fd0%40gmail.com.


Re: How to use ModelChoiceField? I whould like to filter the output from a field form.

2020-04-28 Thread Antje Kazimiers
 qs = TypJob.objects.filter(author__id=user.id)

needs to go inside of the __init__ function. you pass user = request.user
as a parameter to OrderTestForm when you instantiate it in your view and
can use it then in your init function.
Also you can only filter the id of the author if the author field is a
ForeignKey, is it?

Antje

On Tue, Apr 28, 2020 at 9:35 AM Sergei Sokov  wrote:

> I have some models classes. And some classes have bounding fields with
> another class. Each class have the field - author. I whould like that for
> each user the form bounding field shows only those data which was created
> these authors.
>
> For example:
> class “TypeJob” has field “author”.
> User Jhon created a TypJob - “Painting”.
> User Alex created a TypJob - “Cleaning”.
> Class “Order” has bounding field - “name_typ_job”
> When Jhon whould like create an order, he opens the form and click “name
> type job” field, he sees both type job: painting and cleaning.
> I whould like that he sees and could choose only “painting”. Because he is
> it author.
>
>
> I wrote that
>
> class OrderTestForm(forms.ModelForm):
> class Meta:
> model = Order
> name_job = forms.ModelChoiceField(queryset=None)
> qs = TypJob.objects.filter(author__id=user.id)
> def __init__(self, *args, **kwargs):
> super().__init__(*args, **kwargs)
> self.fields['name_job'].queryset = qs
>
> But I have
>
> name ‘user’ is not defined
>
> name ‘author__id’ is not defined
>
> --
> 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/178dcdb1-c119-46ef-83c3-95bda19118c8%40googlegroups.com
> 
> .
>

-- 
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/CAN6tUhmTd%3DmSr5VvbrBhXMWaOBN5eyzhwSaH_ZkW2ZcEYTiaPA%40mail.gmail.com.


Re: How to use ModelChoiceField? I whould like to filter the output from a field form.

2020-04-28 Thread Antje Kazimiers
the form doesn't know the request only the view does. how does your view
function look like?

On 4/28/20 5:57 PM, Sergei Sokov wrote:
> я не совсем понял
>
> |
>     class Meta:
>         model = Order
>         fields = '__all__'
>     name_job = forms.ModelMultipleChoiceField(queryset=None)
>     def __init__(self, *args, **kwargs):
>         super().__init__(*args, **kwargs)
>         qs = TypJob.objects.filter(author__id=request.user.id)
>         self.fields['name_job'].queryset = qs
> |
>
> I have error
> 'NoneType' object has no attribute '_prefetch_related_lookups'
>
>
> вторник, 28 апреля 2020 г., 17:19:01 UTC+2 пользователь hend hend
> написал:
>
> user.id  надо брать из request объекта в
> контроллере request.user.id . В том же
> контроллере метод get_initial() позволяет инициализировать поля
> формы(указанной в аттрибуте "form_class")контроллера.
> Например:
>     def get_initial(self):
>             # поле category формы будет установлено в результат
> выборки по ключу
>             self.initial["category"] =
> Category.objects.get(pk=self.c_id)
>         return self.initial.copy() # 
>
> -- 
> 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/12538865-4221-40e9-92bf-b8efc1ed7309%40googlegroups.com
> .

-- 
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/376307c8-5585-36ed-58dc-f67efc7e6509%40gmail.com.


Re: How to use ModelChoiceField? I whould like to filter the output from a field form.

2020-04-29 Thread Antje Kazimiers
no idea how you do this with a CreateView but with a simple view
function you have a request object:

https://docs.djangoproject.com/en/3.0/topics/http/views/#a-simple-view

this thread is about passing a variable into from the view function to a
form:

https://groups.google.com/forum/#!searchin/django-users/I$20think$20in$20your$20view$20modulesView()$20%7Csort:date/django-users/AtTDAn-M7_E/V7sx7piSCQAJ

Antje

On 4/28/20 6:56 PM, Sergei Sokov wrote:
> |
> forms.py
> classOrderForm(forms.ModelForm):
>     classMeta:
>         model =Order
>     name_job =forms.ModelMultipleChoiceField(queryset=None)
>     def__init__(self,*args,**kwargs):
>         super().__init__(*args,**kwargs)
>         qs =TypJob.objects.filter(author__id=request.user.id)
> |
>
> views.py
> |
> classOrderNewBigPrintView(LoginRequiredMixin,CustomSuccessMessageMixin,CreateView):
>     model =Order
>     template_name ='new_order_bp.html'
>     form_class =OrderForm
>     success_url =reverse_lazy('orders')
>     success_msg ='Ok'
> |
>
> |
> models.py
> classTypJob(models.Model):
>  author =models.ForeignKey(User,on_delete
> =models.CASCADE,verbose_name='author',null=True)
>  name_job =models.CharField('name job',max_length=200)
>
>
> classOrder(models.Model):
>  author =models.ForeignKey(User,on_delete
> =models.CASCADE,verbose_name='author',blank=True,null=True)
>  number_order =models.CharField('number of order',max_length=100)
>  date_create =models.DateTimeField(auto_now=True)
>  name =models.ForeignKey(Customer,on_delete
> =models.CASCADE,verbose_name='customer',null=True)
>  name_order =models.CharField('name of order',max_length=200)
> |
>
>
> вторник, 28 апреля 2020 г., 18:41:25 UTC+2 пользователь Antje
> Kazimiers написал:
>
> the form doesn't know the request only the view does. how does
> your view function look like?
>
> On 4/28/20 5:57 PM, Sergei Sokov wrote:
>> я не совсем понял
>>
>> |
>>     class Meta:
>>         model = Order
>>         fields = '__all__'
>>     name_job = forms.ModelMultipleChoiceField(queryset=None)
>>     def __init__(self, *args, **kwargs):
>>         super().__init__(*args, **kwargs)
>>         qs = TypJob.objects.filter(author__id=request.user.id
>> <http://request.user.id>)
>>         self.fields['name_job'].queryset = qs
>> |
>>
>> I have error
>> 'NoneType' object has no attribute '_prefetch_related_lookups'
>>
>>
>> вторник, 28 апреля 2020 г., 17:19:01 UTC+2 пользователь hend hend
>> написал:
>>
>> user.id <http://user.id> надо брать из request объекта в
>> контроллере request.user.id <http://request.user.id>. В том
>> же контроллере метод get_initial() позволяет инициализировать
>> поля формы(указанной в аттрибуте "form_class")контроллера.
>> Например:
>>     def get_initial(self):
>>             # поле category формы будет установлено в
>> результат выборки по ключу
>>             self.initial["category"] =
>> Category.objects.get(pk=self.c_id)
>>         return self.initial.copy() # 
>>
>> -- 
>> 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...@googlegroups.com.
>> To view this discussion on the web visit
>> 
>> https://groups.google.com/d/msgid/django-users/12538865-4221-40e9-92bf-b8efc1ed7309%40googlegroups.com
>> 
>> <https://groups.google.com/d/msgid/django-users/12538865-4221-40e9-92bf-b8efc1ed7309%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
> -- 
> 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
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/bbbdf319-812c-40e0-9ebf-235efed46a9d%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/bbbdf319-812c-40e0-9ebf-235efed46a9d%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
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/595f75bc-0dc0-0794-1852-e8745d8e4dee%40gmail.com.


Re: Categories and shoe Subcategories according to the parent category.

2020-05-19 Thread Antje Kazimiers
you could have a field "parent" in your Model Category which is a
ForeignKey to Category itself, so Category is a self-referencing table.

Then in your first dropdown you only show those entries where parent is
None and in your second one where parent == accessories.

you need to get this right with your view which would be
show_child_categories where you pass the id of your parent and filter
for it in your view function.

hope that helps, antje

On 5/17/20 11:21 PM, saqlain abbas wrote:
> Hi, if i add Categories , for example 
> 1)accessories
> 2)sports
> 3)books
> Subcategories:
> accessories is the parent category
> child categories are 
> watches
> jewlry
> caps 
> how can i show if  user selects the parent category accessories then
> the subcategories show according to parent categories like
> subcategories are watches jewlry etc
> -- 
> 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/1530c511-072f-44ee-83fa-3555bd090a89%40googlegroups.com
> .

-- 
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/a28636f4-1dbc-b622-e2ce-3a0010625978%40gmail.com.


Re: Django Design Patterns

2019-11-17 Thread Antje Kazimiers
Hi Fatjon,

I wonder how much you can try finding that out on your own by just
grepping for the names of the common Gang of Four [1] - design patterns
in the django source code. I just tried Observer, Factory and find
examples in the code, which sound like the developer really followed the
intention of that pattern, when they named the function / class, which
is good. Another example is Decorator:

> git grep decorator

gives many results, among those the file

django/utils/functional.py

There are the lines of code

def keep_lazy(*resultclasses):
    """
    A decorator that allows a function to be called with one or more lazy
    arguments. If none of the args are lazy, the function is evaluated
    immediately, otherwise a __proxy__ is returned that will evaluate the
    function when needed.
    """
    if not resultclasses:
    raise TypeError("You must pass at least one argument to
keep_lazy().")

    def decorator(func):
    ..
    return decorator

and that to me really looks exactly what the purpose of a decorator is.

Antje

[1] https://en.wikipedia.org/wiki/Gang_of_Four


On 11/17/19 3:40 AM, Fatjon Gërra wrote:
> Hi guys, can anyone suggest me some resources book/video/article where
> I can learn more about Design Patterns that the Django Team used in
> writing Django as a framework? For example, here
>  the
> Active Record pattern is mentioned. I am looking for the other ones. I
> want to dive into Django's source code and learn about Design Patterns
> at the same time. Thanks for the 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/039a922c-a882-4e82-be0b-0ea568850074%40googlegroups.com
> .

-- 
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/91000c02-9596-0a9d-985d-f1a2c2df5562%40gmail.com.


Re: How to run the django development environment?

2020-01-26 Thread Antje Kazimiers
If you want to contribute to django, this README has detailed step-by-step
instructions to get the environment running and links to find tickets to
work on:

https://github.com/carltongibson/dcus2019sprints#getting-set-up-with-the-code

It's been written by Carlton Gibson, who gave a talk about how contribute
to Django at the last DjangoCon US and who led the sprint workshop.


Antje

On Sat, Jan 25, 2020 at 1:50 PM aakansha jain 
wrote:

> I am new to open source. I have forked the project on my system.
> But now I am not getting how to run the django development environment so
> that I can contribute to Django..
>
> --
> 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/39311775-b282-4852-a488-4d1287657b84%40googlegroups.com
> 
> .
>

-- 
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/CAN6tUh%3DfrSx2sp7w10TQpT%3DOvs%3DWRA0yuvM0%3D%2BMR8WX7dpYxrg%40mail.gmail.com.


Re: Can't find image files

2020-01-27 Thread Antje Kazimiers
Hi,

I keep my images files within in a static folder, so

./MyProject/static/media/myimage.png

would be my path. In the template I make use of it like that:



It's explained here:

https://docs.djangoproject.com/en/3.0/howto/static-files/

also that you need to define your static folder in your settings file:
STATIC_URL = '/static/'

and that you might need to run collectstatic first, if your DEBUG
variable is set to false in your settings file.


Kind regards,
Antje


On 1/27/20 7:52 PM, Dick Arnold wrote:
> My nice, new Django application is going along fairly well,  although
> I have run into a couple of roadblocks and need some help. The first
> problem is my HTML  HTML statement:
>
> 
>
> Here's the error message I get on my terminal (command prompt) window:
>
> Not Found: /GAW.jpg
> [25/Jan/2020 11:51:50] "GET /GAW.jpg HTTP/1.1" 404 3481
>
> I read every thing I could find and most of them tell me that it is in
> a location relative to the "current folder", but I can find nothing
> that explains what is meant  by "current".  I thought it might be
> where my terminal prompt comes from.   It's in the highest level
> project folder. Tried that and still no luck.
> -- 
> 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/4dd2997f-0063-4300-b075-404f99569f8e%40googlegroups.com
> .

-- 
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/38aefe7f-45c7-02d7-91f7-674b94509d13%40gmail.com.


Re: Error with filter queryset

2020-02-09 Thread Antje Kazimiers
Hi Chuck,

Status in your example is not a text field, but a Foreign Key, that
means a reference to a record in another table Task_Status, you see that
here:

Status = models.ForeignKey(Task_Status, on_delete=models.CASCADE)

You need to filter on the attribute within Task_Status, which has the
value 'In progress', probably the 'name' attribute:

tasks = Task.objects.filter(Status__name='In progress')


The error says it expects an id, which is the primary key of the
Task_Status record the Task record is referring to.


Hope that helps,
Antje

On 2/9/20 3:31 AM, Chuck G. Madamombe wrote:
> Hello,
>
> I want to filter data in the database to retrieve only those tasks
> with status='In progress'. I have used the filter queryset, but am
> getting an error. Please help.
>
> *Here is my view (Filter tasks by their status):*
>
> def tasks_in_progress(request):
> tasks = Task.objects.filter(Status='In progress')
> context = {'tasks': tasks}
> #return render(request,"todoapp/show_task.html",{'tasks':tasks}) return 
> render(request,"todoapp/tasks_in_progress.html", context)
>
> *The model.py*
> class Task(models.Model):
> #Task_Title = models.ForeignKey(ToDoList, on_delete=models.CASCADE) 
> Task_Title = models.CharField(max_length=500)
> Task_Description = models.CharField(max_length=500)
> Priority = models.ForeignKey(Task_Priority, on_delete=models.CASCADE)
> Date_Created = models.DateTimeField(auto_now_add=True)
> Completion_Date = models.DateTimeField()
> Assigned_To = models.ForeignKey(User, blank=True, null=True, 
> on_delete=models.SET_NULL)
> Status = models.ForeignKey(Task_Status, on_delete=models.CASCADE)
>
> def __str__(self):
> return self.Task_Description
> *The error am getting is:*
>
>
>   ValueError at /todoapp/tasks_in_progress
>
> Field 'id' expected a number but got 'In progress'.
> Request Method:   GET
> Request URL:  http://127.0.0.1:8000/todoapp/tasks_in_progress
> Django Version:   3.0.2
> Exception Type:   ValueError
> Exception Value:  
> Field 'id' expected a number but got 'In progress'.
> Exception Location:   C:\Users\Chuck
> Madamombe\Desktop\djangoPROJECTS\lib\site-packages\django\db\models\fields\__init__.py
> in get_prep_value, line 1772
> Python Executable:C:\Users\Chuck
> Madamombe\Desktop\djangoPROJECTS\Scripts\python.exe
> Python Version:   3.7.1
> Python Path:  
> ['C:\\Users\\Chuck Madamombe\\Desktop\\djangoPROJECTS',
>  'C:\\Users\\Chuck Madamombe\\Desktop\\djangoPROJECTS\\Scripts\\python37.zip',
>  'C:\\Users\\Chuck '
>  'Madamombe\\AppData\\Local\\Programs\\Python\\Python37-32\\DLLs',
>  'C:\\Users\\Chuck '
>  'Madamombe\\AppData\\Local\\Programs\\Python\\Python37-32\\lib',
>  'C:\\Users\\Chuck Madamombe\\AppData\\Local\\Programs\\Python\\Python37-32',
>  'C:\\Users\\Chuck Madamombe\\Desktop\\djangoPROJECTS',
>  'C:\\Users\\Chuck Madamombe\\Desktop\\djangoPROJECTS\\lib\\site-packages',
>  'C:\\Users\\Chuck '
>  
> 'Madamombe\\Desktop\\djangoPROJECTS\\lib\\site-packages\\setuptools-39.1.0-py3.7.egg']
> Server time:  Sun, 9 Feb 2020 10:22:05 +0200
>
>
> But if I just retrieve all the records in the database, without
> filtering, its working without an error
>
>
>
> *My View to retrieve all the records in the database, without filtering.*
>
> def show_task(request):
> tasks = Task.objects.all()
> context = {'tasks': tasks}
> #return render(request,"todoapp/show_task.html",{'tasks':tasks}) return 
> render(request,"todoapp/show_task.html", context)
>
> -- 
> 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/a13041e8-1c37-4722-bf64-4faa75dd56ff%40googlegroups.com
> .

-- 
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/03679dec-cbd3-0890-4a10-afdff2336734%40gmail.com.