Re: Working with forms

2020-04-03 Thread Bruckner de Villiers
Please share code for home.html & urls.py.  Also have you included the app name 
in the settings.py?

Thanks,

 

Bruckner de Villiers

083 625 1086

 

From:  on behalf of Ifeanyi Chielo 

Reply to: 
Date: Saturday, 04 April 2020 at 02:51
To: Django users 
Subject: Re: Working with forms

 

Thanks Victor, 

I did it and it does not make any cnange


On Saturday, April 4, 2020 at 1:41:19 AM UTC+1, victor awakan wrote:

In the form template tag, shouldn’t it be {{ form.as_p}} tag?

 

On Sat 4. Apr 2020 at 3.35, Ifeanyi Chielo  wrote:

Hello,I developed a form with a single field, but this form displays only the 
submit button at the browser as shown in the image below. Please how can I 
correct this and also  save the field to the MySQL table.  My code is also 
shown below

 

View.py 

from django.http import HttpResponseRedirect

from django.shortcuts import render

from .models import Namerec

from .forms import NameForm

from django.views.generic import TemplateView

 

def HomePageView (request, *args, **kwargs):

 return render(request,"home.html", {})

def Namev_view (request):

if request.method == 'POST':

form = NameForm (request.POST)

if NameForm.is_valid():

NameForm.save()

context = {

'form': form

}

return render(request, 'namev.html', {})

form.py

from .models import Namerec

from django import forms

class NameForm(forms.Form):

your_name = forms.CharField(label='Your name', max_length=100)

template (namev.htlm)



{% csrf_token %}

{{ form  }}





 


 

Model.py 

from django.db import models

class Namerec(models.Model):

your_name = models.CharField(max_length=30)

   

 

-- 
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/f50577dd-d5c0-4478-8993-7bab533f24f9%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/9825aec7-7e87-4d4a-80f9-634cb9e4dd59%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/E47A5C26-9855-4ED7-86AD-3F427A2E88B7%40gmail.com.


Re: A question about the Django server

2020-03-20 Thread Bruckner de Villiers
Have you set up your admin.py?

 

Bruckner de Villiers

083 625 1086

 

From:  on behalf of Liu楽叁 

Reply to: 
Date: Friday, 20 March 2020 at 14:05
To: Django users 
Subject: A question about the Django server

 

I am using windows and I started a server by 'py manage.py runserver' in the 
powershell, It works

and I also can visit the web I writed for test

but when I try to login the background, the server is break down

 

I have tried so hard to find out what's the problem, but still can not fix it. 
so I am asking for your help and advice. 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/6054fc39-21a1-4e72-8edc-4c17a838d41f%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/72428AAE-C944-4C58-9FC2-0A1665819458%40gmail.com.


Re: Any newbies especially in Cape Town for meetups?

2020-02-17 Thread Bruckner de Villiers
Why not start a Django Meetup Group?  There is already a Python Meetup Group.  
I would be interested.
Regards,

Bruckner de Villiers
083 625 1086

On 2020/02/16, 12:16, "Perceval Maturure"  wrote:

That’s a good point. How about, could you elaborate on how this can be 
done? Skype calls? Skype groups?
Please share what you have in mind
Regards
Perceval

> On 15 Feb 2020, at 23:42, Francis Butawu  wrote:
> 
> Hi All
> 
> I'm new to Django and I'm looking for some people to organize a meetup 
with and learn from each other ideally those in Cape Town pls reach out 
> 
> -- 
> 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/841891a5-2df4-4c2e-ab5c-6f2ee7a9b44d%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/38F77DB0-2AE3-4257-BE5A-32C1E819C6CB%40gmail.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/CDB75CDD-959F-4576-B12B-A66BA455C550%40gmail.com.


Re: AutoField & auto-incrementing

2020-02-12 Thread Bruckner de Villiers
Useful, thanks Mike.

Bruckner de Villiers
083 625 1086

On 2020/02/12, 23:18, "Mike Dewhirst"  wrote:

On 12/02/2020 6:54 pm, Mike Dewhirst wrote:
> def save(self, *args, **kwargs):
> self._pre_save()# stuff to be computed pre-save
> super().save(*args, **kwargs)
> self._post_save()   # stuff to be done after the save

Also of occasional value ...

def save(self, *args, **kwargs):
 whatever = self._pre_save()# returns something needed by 
_post_save()
 super().save(*args, **kwargs)
 self._post_save(whatever)  # gets input across the super () 
boundary

Cheers

Mike


-- 
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/c012d154-fb3a-046a-5e48-0a9d838e2119%40dewhirst.com.au.



-- 
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/AF58CFD3-61EC-4399-BA00-4FD7CE2C7496%40gmail.com.


Re: AutoField & auto-incrementing

2020-02-12 Thread Bruckner de Villiers
Thanks Mike - I have just become cleverer.

Bruckner de Villiers
083 625 1086

On 2020/02/12, 09:55, "Mike Dewhirst"  wrote:

On 12/02/2020 6:11 pm, Bruckner de Villiers wrote:
> Mike,
> Clever.  The save function seems to write a string of the id.  So, 
self.formulation_no = "50-" + str(self.id) could also work?

Fact is you can do anything you like. Instead of what I showed you could 
call any method you care to write either before or after the super() 
call in model.save()

You can also use pre_save and post_save signals to do much the same thing.

Where I need to do such things my preference is a model save method 
which looks like this ...

def save(self, *args, **kwargs):
 self._pre_save()# stuff to be computed pre-save
 super().save(*args, **kwargs)
 self._post_save()   # stuff to be done after the save

Specifically, yes my requirement was to have a models.CharField so 
str(self.id) was the way to satisfy that.

Cheers

Mike
    
>
> Bruckner de Villiers
> +27 83 625 1086
>
> On 2020/02/12, 00:27, "Mike Dewhirst"  wrote:
    >
>  On 11/02/2020 7:06 pm, Bruckner de Villiers wrote:
>  >
>  > Jason,
>  >
>  > Thank you.  I have changed the title of this mail.  If I have read 
the
>  > 10 year old ticket 8576 correctly, it seems to be a DB restriction 
and
>  > I imagine that there are good reasons for this.  However, then I 
don’t
>  > understand the purpose of the AutoField given the restrictions and
>  > that the Django documentation is somewhat ambiguous/vague.
>  >
>  > The options seem to be:
>  >
>  >   * Your uuid suggestion (which I have never worked with, but will
>  > explore)
>  >   * a function in the model that does the incrementing before
>  > committing – (anyone have some example code for this?).  The
>  > challenge would be to keep track of the last used ticket no.  I
>  > haven’t thought this through yet, but it does occur to me that 
one
>  > could use the id (maybe prefix the id with some starting 
digits)
>  > and write the record twice. Probably barking up the wrong tree.
>  >
>  
>  I have a need for a unique identifier in one of my models. I save 
the id
>  to a separate field in the same model. In my case I don't need to see
>  the value. It just needs to be unique and never change. It is used 
for
>  generating the equivalent of a bar-code in a different model.
>  
>   def save(self, *args, **kwargs):
>   if self.id:
>   if not self.formulation_no:
>   self.formulation_no = str(self.id)
>   super().save(*args, **kwargs)
>  
>  A downside to this is the formulation number stays blank until the 
next
>  save after creating the record. The upside is that the id isn't 
going to
>  change so uniqueness isn't lost. Another way of doing this is to copy
>  the id when it is first required and formulation_no is still blank.
>  
>  I have also been known to use a weird mechanism for user-resequencing
>  records in a display. In that case they are lesson sequences within a
>  course and question sequences within a lesson. I use floats and 
strings
>  in a pair of fields so if that is of interest just ask.
>  
>  Cheers
>  
>  Mike
>  
>  >  *
>  >
>  > Regards,
>  >
>  > Bruckner de Villiers
>  >
>  > +27 83 625 1086
>  >
>  > *From: * on behalf of Jason
>  > 
>  > *Reply to: *
>  > *Date: *Monday, 10 February 2020 at 14:55
>  > *To: *Django users 
>  > *Subject: *Re: Adding a verbose_name to id field
>  >
>  > Hmm.  TIL about https://code.djangoproject.com/ticket/8576
>  >
>  > Would a a uuid for this, rather than an integer?  If not, you'll 
have
>  > to implement a save override to handle the incrementing yourself.
>  >
>  > In addition, it might be worthwhile bringing this ticket up for
>  > discussion at 
https://groups.google.com/forum/#!forum/django-developers
>  >
>  > --
>  > You received this message because y

Re: AutoField & auto-incrementing

2020-02-11 Thread Bruckner de Villiers
Mike,
Clever.  The save function seems to write a string of the id.  So, 
self.formulation_no = "50-" + str(self.id) could also work?

Bruckner de Villiers
+27 83 625 1086

On 2020/02/12, 00:27, "Mike Dewhirst"  wrote:

On 11/02/2020 7:06 pm, Bruckner de Villiers wrote:
>
> Jason,
>
> Thank you.  I have changed the title of this mail.  If I have read the 
> 10 year old ticket 8576 correctly, it seems to be a DB restriction and 
> I imagine that there are good reasons for this.  However, then I don’t 
> understand the purpose of the AutoField given the restrictions and 
> that the Django documentation is somewhat ambiguous/vague.
>
> The options seem to be:
>
>   * Your uuid suggestion (which I have never worked with, but will
> explore)
>   * a function in the model that does the incrementing before
> committing – (anyone have some example code for this?).  The
> challenge would be to keep track of the last used ticket no.  I
> haven’t thought this through yet, but it does occur to me that one
> could use the id (maybe prefix the id with some starting digits)
> and write the record twice. Probably barking up the wrong tree.
>

I have a need for a unique identifier in one of my models. I save the id 
to a separate field in the same model. In my case I don't need to see 
the value. It just needs to be unique and never change. It is used for 
generating the equivalent of a bar-code in a different model.

 def save(self, *args, **kwargs):
 if self.id:
 if not self.formulation_no:
 self.formulation_no = str(self.id)
 super().save(*args, **kwargs)

A downside to this is the formulation number stays blank until the next 
save after creating the record. The upside is that the id isn't going to 
change so uniqueness isn't lost. Another way of doing this is to copy 
the id when it is first required and formulation_no is still blank.

I have also been known to use a weird mechanism for user-resequencing 
records in a display. In that case they are lesson sequences within a 
course and question sequences within a lesson. I use floats and strings 
in a pair of fields so if that is of interest just ask.

    Cheers
    
Mike

>  *
>
> Regards,
>
> Bruckner de Villiers
>
> +27 83 625 1086
>
> *From: * on behalf of Jason 
> 
> *Reply to: *
> *Date: *Monday, 10 February 2020 at 14:55
> *To: *Django users 
> *Subject: *Re: Adding a verbose_name to id field
>
> Hmm.  TIL about https://code.djangoproject.com/ticket/8576
>
> Would a a uuid for this, rather than an integer?  If not, you'll have 
> to implement a save override to handle the incrementing yourself.
>
> In addition, it might be worthwhile bringing this ticket up for 
> discussion at https://groups.google.com/forum/#!forum/django-developers
>
> -- 
> 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/dc686528-0a8d-43ff-9973-d478cc765959%40googlegroups.com
 
> 
<https://groups.google.com/d/msgid/django-users/dc686528-0a8d-43ff-9973-d478cc765959%40googlegroups.com?utm_medium=email_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/7C1BE52B-AFAE-4D38-9003-8A454A284A39%40gmail.com
 
> 
<https://groups.google.com/d/msgid/django-users/7C1BE52B-AFAE-4D38-9003-8A454A284A39%40gmail.com?utm_medium=email_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/99dbcba0-22bd-7c1d-5fe6-68984353bfb1%40dewhirst.com.au.



-- 
You receive

Re: AutoField & auto-incrementing

2020-02-11 Thread Bruckner de Villiers
Jason,

I cracked the uuid option – what an ugly ticket no.!!! - 
0273051c-af54-4baf-91b9-651701d9020c

 

Bruckner de Villiers

083 625 1086

 

From: Bruckner de Villiers 
Date: Tuesday, 11 February 2020 at 10:06
To: 
Subject: AutoField & auto-incrementing

 

Jason,

Thank you.  I have changed the title of this mail.  If I have read the 10 year 
old ticket 8576 correctly, it seems to be a DB restriction and I imagine that 
there are good reasons for this.  However, then I don’t understand the purpose 
of the AutoField given the restrictions and that the Django documentation is 
somewhat ambiguous/vague.

 

The options seem to be:
Your uuid suggestion (which I have never worked with, but will explore)
a function in the model that does the incrementing before committing – (anyone 
have some example code for this?).  The challenge would be to keep track of the 
last used ticket no.  I haven’t thought this through yet, but it does occur to 
me that one could use the id (maybe prefix the id with some starting digits) 
and write the record twice.  Probably barking up the wrong tree.
Regards,

 

Bruckner de Villiers

+27 83 625 1086

 

From:  on behalf of Jason 
Reply to: 
Date: Monday, 10 February 2020 at 14:55
To: Django users 
Subject: Re: Adding a verbose_name to id field

 

Hmm.  TIL about https://code.djangoproject.com/ticket/8576

 

Would a a uuid for this, rather than an integer?  If not, you'll have to 
implement a save override to handle the incrementing yourself.

 

In addition, it might be worthwhile bringing this ticket up for discussion at 
https://groups.google.com/forum/#!forum/django-developers

-- 
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/dc686528-0a8d-43ff-9973-d478cc765959%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/3385BD9A-F8CB-442C-92C0-151139316082%40gmail.com.


AutoField & auto-incrementing

2020-02-11 Thread Bruckner de Villiers
Jason,

Thank you.  I have changed the title of this mail.  If I have read the 10 year 
old ticket 8576 correctly, it seems to be a DB restriction and I imagine that 
there are good reasons for this.  However, then I don’t understand the purpose 
of the AutoField given the restrictions and that the Django documentation is 
somewhat ambiguous/vague.

 

The options seem to be:
Your uuid suggestion (which I have never worked with, but will explore)
a function in the model that does the incrementing before committing – (anyone 
have some example code for this?).  The challenge would be to keep track of the 
last used ticket no.  I haven’t thought this through yet, but it does occur to 
me that one could use the id (maybe prefix the id with some starting digits) 
and write the record twice.  Probably barking up the wrong tree.
Regards,

 

Bruckner de Villiers

+27 83 625 1086

 

From:  on behalf of Jason 
Reply to: 
Date: Monday, 10 February 2020 at 14:55
To: Django users 
Subject: Re: Adding a verbose_name to id field

 

Hmm.  TIL about https://code.djangoproject.com/ticket/8576

 

Would a a uuid for this, rather than an integer?  If not, you'll have to 
implement a save override to handle the incrementing yourself.

 

In addition, it might be worthwhile bringing this ticket up for discussion at 
https://groups.google.com/forum/#!forum/django-developers

-- 
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/dc686528-0a8d-43ff-9973-d478cc765959%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/7C1BE52B-AFAE-4D38-9003-8A454A284A39%40gmail.com.


Re: to add counter to an object of a table

2020-02-10 Thread Bruckner de Villiers
Brajesh,

I presume that you want the counter to auto-increment.  The gurus are 
recommending AutoField, but I can’t get it to work yet and the Django docs are 
a bit vague on the subect.

Good luck.

 

Bruckner de Villiers

083 625 1086

 

From:  on behalf of BRAJESH KUMAR 

Reply to: 
Date: Sunday, 09 February 2020 at 20:45
To: "django-users@googlegroups.com" 
Subject: to add counter to an object of a table

 

Hi ,

I have a product details db class with few details for each object of that 
class, need help to add a counter.

 

Thanks,

Brajesh

 

 

Sent from Mail for Windows 10

 

-- 
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/5e405315.1c69fb81.6e215.a4ec%40mx.google.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/3467A551-64FD-4D20-9174-3C4667A1224B%40gmail.com.


Re: Adding a verbose_name to id field

2020-02-10 Thread Bruckner de Villiers
 

Thank you Jason.  However, I get the following error - AssertionError: Model 
bugs.Bugs can't have more than one auto-generated field.  Before adding the 
underlined bug_ticket field everything worked.  Is the error because the model 
already exists and I am adding the AutoField?

 

My models.py:

 

class Bugs(models.Model):

    FUNCTION_CHOICES = [

    ('C', 'Contacts'),

    ('E', 'Execs'),

    ('I', 'Sector/Industry'),

    ('G', 'General'),

    ('L', 'Clients'),

    ('O', 'Organisations'),

    ('P', 'Opportunities'),

    ('S', 'Account Type'),

    ('T', 'Training Material'),

    ('U', 'Currencies'),

    

]

    BUGTYPE_CHOICES = [

    ('B', 'Bug'),

    ('C', 'Comment'),

    ('S', 'Suggestion'),

    ]

    CLOSED_CHOICES = [

    ('N', 'No'),

    ('W', 'Work in Progress'),

    ('Y', 'Yes'),

    ]

    bug_ticket = models.AutoField(primary_key=False)

    bug_author = models.ForeignKey('auth.User', on_delete=models.CASCADE, 
verbose_name="Issue Author")

    bug_title = models.CharField(max_length=200, verbose_name="Brief 
Description:")

    bug_type = models.CharField(max_length=1, choices=BUGTYPE_CHOICES, 
verbose_name="Issue Type")

    bug_function = models.CharField(max_length=1, default="G", 
choices=FUNCTION_CHOICES, verbose_name="Function")

    bug_text = models.TextField()

    bug_status = models.CharField(max_length=1, default="N", 
choices=CLOSED_CHOICES, verbose_name="Issue addressed?")

    bug_created_date = models.DateTimeField(auto_now_add=True)

    bug_published_date = models.DateTimeField(blank=True, null=True)

    bug_update_date = models.DateTimeField(auto_now=True, verbose_name="Last 
Updated:")

 

    class Meta:

    verbose_name_plural="Bugs"

    

 

    def publish(self):

    self.published_date = timezone.now()

    self.save()

 

    def approve_comments(self):

    return self.comments.filter(approved_comment=True)

 

    def get_absolute_url(self):

    print(self.pk)

    return reverse("bugs/bug_detail",kwargs={'pk':self.pk})

 

    def __str__(self):

    return self.bug_title

 

 

Thanks for your attention to date.

 

Bruckner de Villiers

083 625 1086

 

From:  on behalf of Jason 
Reply to: 
Date: Monday, 10 February 2020 at 01:21
To: Django users 
Subject: Re: Adding a verbose_name to id field

 

You just need to use AutoField

-- 
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/3f0ecd5b-9493-47dd-bf85-382e87c3efd9%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/5986FDFB-B039-465C-BA2A-04EF9816A190%40gmail.com.


Re: Adding a verbose_name to id field

2020-02-09 Thread Bruckner de Villiers
Thank you Mike & Jason.

I agree - messing around with the id is not the brightest idea I've ever 
conceived.
However, the Django 3 documentation is somewhat mute on auto-incrementing, but 
I'll continue searching Stack & Mozilla.  Have a great evening (I am GMT+2).
Regards,

Bruckner de Villiers
083 625 1086

On 2020/02/09, 08:28, "Mike Dewhirst"  wrote:

On 9/02/2020 3:54 am, Bruckner de Villiers wrote:
>
> Mike,
>
> I tried id = model.AutoField(verbose_name=”Ticket #”).  Migrate didn’t 
> like it – can’t have duplicate primaries.  I suspect this is because 
> the Bug model already exists.
>
> What I am trying to achieve is an auto-increment field whereby every 
> time a user logs a bug/suggestion/comment it writes a unique ticket 
> number in the background, which is used as a reference for subsequent 
> actions like Fixed, Close, WiP, etc.  and as a ForeignKey in the 
> Comment model.   I couldn’t find anything meaningful for this 
> functionality and so thought that the ‘id’ is already fit for purpose, 
> but merely requires an explanatory field text.
>

I think Jason is correct. The id field belongs to the DBMS and 
theoretically should never carry any human or real world meaning.

You would be better having an auto-incrementing field called "ticket" or 
similar

If you really must use the id field you can supply the model with your 
own id field (that's covered somewhere in the docs) with whatever name 
suits.
    
Cheers

    Mike



> Make sense?
>
> Bruckner de Villiers
>
> 083 625 1086
>
> *From: * on behalf of Mike Dewhirst 
> 
> *Reply to: *
> *Date: *Saturday, 08 February 2020 at 13:48
> *To: *
> *Subject: *RE: Adding a verbose_name to id field
>
> I imagine you need to specify the id field in your model and give it a 
> verbose name.
>
> This is an unusual requirement. Why do you want to do such a thing?
>
> Mike
>
>  Original message 
>
> From: Bruckner de Villiers 
>
> Date: 8/2/20 21:33 (GMT+10:00)
>
> To: django-users@googlegroups.com
>
> Subject: Adding a verbose_name to id field
>
> Using Sqlite3 & Django 3.0.2 - I have searched high and low, but can’t 
> find a way to add a verbose name to the id of a model.
>
> Anyone have ideas, please?
>
> Bruckner de Villiers
>
> +27 83 625 1086
>
> -- 
> 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/5e3e9fe6.1c69fb81.7cda5.a2fdSMTPIN_ADDED_MISSING%40gmr-mx.google.com
 
> 
<https://groups.google.com/d/msgid/django-users/5e3e9fe6.1c69fb81.7cda5.a2fdSMTPIN_ADDED_MISSING%40gmr-mx.google.com?utm_medium=email_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/CA217C44-C4FE-4CE8-8479-97B9F05939BE%40gmail.com
 
> 
<https://groups.google.com/d/msgid/django-users/CA217C44-C4FE-4CE8-8479-97B9F05939BE%40gmail.com?utm_medium=email_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/2ad77dc8-e743-8241-7531-378bb7f717af%40dewhirst.com.au.



-- 
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/7DF8F99B-92E1-4DFA-84A7-FD63ECCC06E6%40gmail.com.


Re: Adding a verbose_name to id field

2020-02-08 Thread Bruckner de Villiers
Mike,

I tried id = model.AutoField(verbose_name=”Ticket #”).  Migrate didn’t like it 
– can’t have duplicate primaries.  I suspect this is because the Bug model 
already exists.

 

What I am trying to achieve is an auto-increment field whereby every time a 
user logs a bug/suggestion/comment it writes a unique ticket number in the 
background, which is used as a reference for subsequent actions like Fixed, 
Close, WiP, etc.  and as a ForeignKey in the Comment model.   I couldn’t find 
anything meaningful for this functionality and so thought that the ‘id’ is 
already fit for purpose, but merely requires an explanatory field text.

 

Make sense?

 

Bruckner de Villiers

083 625 1086

 

From:  on behalf of Mike Dewhirst 

Reply to: 
Date: Saturday, 08 February 2020 at 13:48
To: 
Subject: RE: Adding a verbose_name to id field

 

I imagine you need to specify the id field in your model and give it a verbose 
name. 

 

This is an unusual requirement. Why do you want to do such a thing?

 

Mike

 

 Original message 

From: Bruckner de Villiers  

Date: 8/2/20 21:33 (GMT+10:00) 

To: django-users@googlegroups.com 

Subject: Adding a verbose_name to id field 

 

Using Sqlite3 & Django 3.0.2 - I have searched high and low, but can’t find a 
way to add a verbose name to the id of a model.

Anyone have ideas, please?

 

Bruckner de Villiers

+27 83 625 1086

-- 
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/5e3e9fe6.1c69fb81.7cda5.a2fdSMTPIN_ADDED_MISSING%40gmr-mx.google.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/CA217C44-C4FE-4CE8-8479-97B9F05939BE%40gmail.com.


Adding a verbose_name to id field

2020-02-08 Thread Bruckner de Villiers
Using Sqlite3 & Django 3.0.2 - I have searched high and low, but can’t find a 
way to add a verbose name to the id of a model.

Anyone have ideas, please?

 

Bruckner de Villiers

+27 83 625 1086

-- 
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/62D60B90-C46E-41AB-AF46-4CD1BEA89D14%40gmail.com.


Re: Backward migration failing because of old dropped model

2020-01-20 Thread Bruckner de Villiers
Adrien,

Your precise issue eludes me, but I have sometimes come across a similar issue 
when changing the field types of models.  

It appears that you still have a reference somewhere in your code between the 
form and the model.  I suspect that form.Form.ticket_description is a Django 
default expected file name from one of your (original) CBV’s.

 

Alternative:

My method to resolve the Catch22 is to delete the most recent migration files, 
including in your case, the migration file that originally created the 
‘ticketdescription’ model.  I move them to a dummy folder, in case they 
shouldn’t have been deleted.

 

Bruckner de Villiers

083 625 1086

 

From:  on behalf of Adrien Agnel 

Reply to: 
Date: Monday, 20 January 2020 at 22:07
To: Django users 
Subject: Backward migration failing because of old dropped model

 

Hi everyone,

 

This is my first post in this group so do not hesitate to ask for some more 
specific details if this is not enough. Django version is 2.2.9, Python 3.6.

 

 

I'm facing an error when trying to migrate back the initial migration of a 
freshly installed new application 'billing'.

The error message is the following one : 

ValueError: The field form.Form.ticket_description was declared with a lazy 
reference to 'tickets.ticketdescription', but app 'tickets' doesn't provide 
model 'ticketdescription'.

 

However the model 'ticketdescription' has been dropped several month ago and is 
no longer present in my project. Thus the part " app 'tickets' doesn't provide 
model 'ticketdescription' " is perfectly right, but I don't get why it is not 
managed by the migration of app 'tickets' which dropped the model 
'ticketdescription'.

The model 'ticketdescription' remains as a pending model of state apps in the 
migration executor, I would expect it to be removed.

 

Until now, I could migrate backward other apps without any issue but after 
adding the app 'billing', which is not directly related to app 'tickets', it is 
not possible anymore.

 

 

 

I don't know where to look at to fix this issue ? Could you help me debugging 
please ? This looks like a bug but I'm not sure !

 

Best regards,

Adrien

 

 

 

 

Here is the full error trace :

 

Traceback (most recent call last):
  File "manage.py", line 23, in 
execute_from_command_line(sys.argv)
  File "[...]/lib/python3.6/site-packages/django/core/management/__init__.py", 
line 381, in execute_from_command_line
utility.execute()
  File "[...]/lib/python3.6/site-packages/django/core/management/__init__.py", 
line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "[...]/lib/python3.6/site-packages/django/core/management/base.py", line 
323, in run_from_argv
self.execute(*args, **cmd_options)
  File "[...]/lib/python3.6/site-packages/django/core/management/base.py", line 
364, in execute
output = self.handle(*args, **options)
  File "[...]/lib/python3.6/site-packages/django/core/management/base.py", line 
83, in wrapped
res = handle_func(*args, **kwargs)
  File 
"[...]/lib/python3.6/site-packages/django/core/management/commands/migrate.py", 
line 234, in handle
fake_initial=fake_initial,
  File "[...]/lib/python3.6/site-packages/django/db/migrations/executor.py", 
line 121, in migrate
state = self._migrate_all_backwards(plan, full_plan, fake=fake)
  File "[...]/lib/python3.6/site-packages/django/db/migrations/executor.py", 
line 173, in _migrate_all_backwards
for migration, _ in full_plan:
  File "[...]/lib/python3.6/site-packages/django/utils/functional.py", line 80, 
in __get__
res = instance.__dict__[self.name] = self.func(instance)
  File "[...]/lib/python3.6/site-packages/django/db/migrations/state.py", line 
210, in apps
return StateApps(self.real_apps, self.models)
  File "[...]/lib/python3.6/site-packages/django/db/migrations/state.py", line 
280, in __init__
raise ValueError("\n".join(error.msg for error in errors))
ValueError: The field form.Form.ticket_description was declared with a lazy 
reference to 'tickets.ticketdescription', but app 'tickets' doesn't provide 
model 'ticketdescription'.

-- 
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/4f876052-71e5-4d25-9382-59d3c30d19f8%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/160DD2D0-2302-41E8-B1B7-CE871AB3A11F%40gmail.com.


Re: Django Lessons

2020-01-19 Thread Bruckner de Villiers
Eugen,

As a Newbie, I found  most of it useful.

Well done.

 

Bruckner de Villiers

083 625 1086

 

From:  on behalf of Eugen Ciur 

Reply to: 
Date: Sunday, 19 January 2020 at 21:56
To: Django users 
Subject: Django Lessons

 

Hi everyone,

 

I launched recently a new resource, django-lessons.com.

I target mostly intermediate django developers but newcomers might find it 
usefull as well.

Although main focus is Django Web Framework, I will post a lot of info about 
devops ecosystem around django (production) and about python itself.

I have an youtube channel as well.

 

What do you think?

-- 
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/0437652e-7887-48f5-a9b8-f0e79bd16d1f%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/522F431F-28FC-48D3-8354-F17C818C8A10%40gmail.com.


Re: Model Related Issue

2020-01-15 Thread Bruckner de Villiers
I guess that this is a fundamental change to the db – Best to first delete the 
old model and start again.

 

Bruckner de Villiers

083 625 1086

 

From:  on behalf of ROHIT CHAUHAN 

Reply to: 
Date: Wednesday, 15 January 2020 at 12:33
To: 
Subject: Re: Model Related Issue

 

manually change in migrations --> 0001_initial.py

 

On Tue, 14 Jan 2020 at 18:10, Soumen Khatua  wrote:

Hi Folks,

 

After changing the model name,I'm getting some error, like initially my model 
name was some thing like this:

class new_model(models.Model) but now I'm change it to class 
NewModel(models.Model) but after migrate I'm getting this error:

 

File 
"/home/sou/tildehat_platform/env/lib/python3.6/site-packages/django/db/migrations/state.py",
 line 280, in __init__
raise ValueError("\n".join(error.msg for error in errors))
ValueError: The field admin.LogEntry.user was declared with a lazy reference to 
'profiles.tildehatuser', but app 'profiles' doesn't provide model 
'tildehatuser'.
The field job_post.job_post.user was declared with a lazy reference to 
'profiles.tildehatuser', but app 'profiles' doesn't provide model 
'tildehatuser'.
The field profiles.tildehat_profile.user was declared with a lazy reference to 
'profiles.tildehatuser', but app 'profiles' doesn't provide model 
'tildehatuser' 

 

Note: I already added the customized model name in settings.py like 
'profiles.ClassName".

 

Please help me guys regarding this matter but I alreday spent so much time on 
this o internet.

 

Thank You in advance

 

Regards,

Soumen

 

-- 
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/CAPUw6WYxGmBjrZugMhLdS%3DFpD0ALEDEq2Bg-3LEfODjUKs5j0g%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/CAF_q%3DRAbNp%3DFcyPRZaZ%3DV6O1G9y5AD0UpZLfN4ELnag_NX44zQ%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/EAF4BF25-1DD0-4F35-8F7C-D7AB955E69F1%40gmail.com.


Pagination in Admin class

2020-01-11 Thread Bruckner de Villiers
Does anyone have some example code to achieve pagination to display a model 
with many records in Admin, please?

 

admin.py – 

 

class CurrencyAdmin(admin.ModelAdmin):

    paginate_by=10

    list_display = ('id', 'currency_Code', 'currency_Description')

    fieldsets = (

    (None, {'fields':('currency_Code', 'currency_Description')}),

    )

 

Much obliged,

 

Bruckner de Villiers

083 625 1086

-- 
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/09547993-6AD3-4118-8F06-9A85193E3A4C%40gmail.com.


Re: unable to execute 'workon' command

2019-12-12 Thread Bruckner de Villiers
https://stackoverflow.com/questions/29900090/virtualenv-workon-doesnt-work

 

 

Bruckner de Villiers

083 625 1086

 

From:  on behalf of rishabh roy 

Reply to: 
Date: Friday, 13 December 2019 at 07:38
To: 
Subject: Re: unable to execute 'workon' command

 

I am student trying to do the project..could anyone suggest anything..

 

On Wed, Dec 11, 2019 at 5:53 PM rishabh roy  wrote:

I am unable get into a virtualenv in vscode:

 c:\Users\User\test\Lib\site-packages>python -m workon tygu

C:\Users\User\test\Scripts\python.exe: No module named workon.__main__; 
'workon' is a package and cannot be directly executed

 

workon is present in  c:\Users\User\test\Lib\site-packages

tygu is the venv

-- 
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/d8065e6b-9643-4088-a3a4-ae013c53faca%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/CAHNVAjfY6aeWSsTa9Qy80VB3ogQb2OXb0qx9jQpX7SDqbRQweA%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/B5AC8D3B-EEFE-4C31-B97C-07BA5E411BB2%40gmail.com.


Re: Multiple Apps in one project with one database

2019-12-11 Thread Bruckner de Villiers
OK, got it.  Changed polls2/views.py to “from polls.models import Choice, 
Question” instead of “from .models import Choice, Question”.  It works, but 
VSCode doesn’t like “polls.model” – it gives a warning “unresolved import”.

Much obliged,

 

Bruckner de Villiers

083 625 1086

 

From:  on behalf of Miracle 

Reply to: 
Date: Wednesday, 11 December 2019 at 12:26
To: 
Subject: Re: Multiple Apps in one project with one database

 

Multiple Apps can point to one database.

 

What happens is that django creates different tables in the database.

 

It uses this format to create the tables

 

'appname_modelname'

 

e.g.  polls_question

 

 

Infact, if you  remember earlier on before runnung your first "python manage.py 
migrate".  Django told you that you had "unapplied migrations"

 

When you applied the migrations you might have noticed some other tables were 
created in the database. Tables like auth, session, admin, etc

 

 

 

On Wed, 11 Dec 2019, 10:52 am Bruckner de Villiers, 
 wrote:

I got to generic views (CBV’s) in part 4 of the Django tutorials and decided 
instead of overwriting  the function views that I would get some practice by 
creating a new app (polls2).  The file structure is identical to the polls app, 
but obviously the code is different for the generic views and urls now pointing 
to polls2.  I ran migrate and makemigrations.  The makemigrations surprised me 
as it created Question & Choice tables again:

(pyfun) Bruckners-MacBook-Pro:mysite brucknerdevilliers$ python manage.py 
makemigrations

Migrations for 'polls2':

  polls2/migrations/0001_initial.py

- Create model Question

- Create model Choice

(pyfun) Bruckners-MacBook-Pro:mysite brucknerdevilliers$ python manage.py 
migrate

Operations to perform:

  Apply all migrations: admin, auth, contenttypes, polls, polls2, sessions

Running migrations:

  Applying polls2.0001_initial... OK

So, I looked at the folders and there is only one sqlite3 file.  The Database 
Structure is unchanged and the original data is still intact.  The admin page 
now displays 2 Question tables – the 2nd one contains no data.  Also, 
http://127.0.0.1:8000/polls2/ shows No Questions available.

 

 

 

I have probably messed up with models.py.  Any pointers please as how multiple 
apps can point to the same database?

Regards,

Bruckner de Villiers

+27(0)83 625 1086

-- 
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/63C629FA-DB68-4CC0-989D-1D346632CD94%40gmail.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/CADZv-jDYH3c%2Brx-d%2BE9C50cCkFnsb80YztQ8V1RXQ_rLEfqojg%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/4F9BFA18-7303-4EF5-AD46-2014CACF0D19%40gmail.com.


Re: SuperUser not logging out after reboot

2019-12-11 Thread Bruckner de Villiers
Thank you – thought that this is the case.  However, I am trying to cater for 
the user who forgot to log out.

Regards,

 

Bruckner de Villiers

083 625 1086

 

From:  on behalf of Miracle 

Reply to: 
Date: Wednesday, 11 December 2019 at 12:09
To: 
Subject: Re: SuperUser not logging out after reboot

 

Hello,

 

If you don't want to be logged in, you can simply log out before closing the 
local server. 

Another way is to tell your browser not to save the password whenever you are 
logging in.

 

 

I suppose you have atleast one email account or social media account. And I 
believe it logs you in automatically even after reboot.

 

In a nutshell, this is an expected behaviour.

 

 You can also clear the clear your browser cache for the page with "shift + F5"

 

Regards 

 

 

On Wed, 11 Dec 2019, 10:20 am Bruckner de Villiers, 
 wrote:

Running Django 3, Python 3.7.3, Chrome Browser on MacOS Catalina.

 

All the code and db are on an external Volume.

 

After a reboot (Restart on Mac), http://127.0.0.1:8000/admin/ displayed the 
admin page without requesting a login.  Not good for serious apps.  Probably 
something in my Chrome setup.  Is there a way to log out a user automatically 
after a set period of time?

 

Much obliged,

 

Bruckner de Villiers

083 625 1086

-- 
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/B80B7331-65D7-41DE-A22E-601A764E6A07%40gmail.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/CADZv-jACi8PXe5Q%2BtXWZ9YvD2UkfdGcbwc686qY03Bv-1FB9sA%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/D973DEBF-27FE-4282-BA99-1BA110F9E2FC%40gmail.com.


Multiple Apps in one project with one database

2019-12-11 Thread Bruckner de Villiers
I got to generic views (CBV’s) in part 4 of the Django tutorials and decided 
instead of overwriting  the function views that I would get some practice by 
creating a new app (polls2).  The file structure is identical to the polls app, 
but obviously the code is different for the generic views and urls now pointing 
to polls2.  I ran migrate and makemigrations.  The makemigrations surprised me 
as it created Question & Choice tables again:

(pyfun) Bruckners-MacBook-Pro:mysite brucknerdevilliers$ python manage.py 
makemigrations

Migrations for 'polls2':

  polls2/migrations/0001_initial.py

    - Create model Question

    - Create model Choice

(pyfun) Bruckners-MacBook-Pro:mysite brucknerdevilliers$ python manage.py 
migrate

Operations to perform:

  Apply all migrations: admin, auth, contenttypes, polls, polls2, sessions

Running migrations:

  Applying polls2.0001_initial... OK

So, I looked at the folders and there is only one sqlite3 file.  The Database 
Structure is unchanged and the original data is still intact.  The admin page 
now displays 2 Question tables – the 2nd one contains no data.  Also, 
http://127.0.0.1:8000/polls2/ shows No Questions available.

 

 

 

I have probably messed up with models.py.  Any pointers please as how multiple 
apps can point to the same database?

Regards,

Bruckner de Villiers

+27(0)83 625 1086

-- 
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/63C629FA-DB68-4CC0-989D-1D346632CD94%40gmail.com.


SuperUser not logging out after reboot

2019-12-11 Thread Bruckner de Villiers
Running Django 3, Python 3.7.3, Chrome Browser on MacOS Catalina.

 

All the code and db are on an external Volume.

 

After a reboot (Restart on Mac), http://127.0.0.1:8000/admin/ displayed the 
admin page without requesting a login.  Not good for serious apps.  Probably 
something in my Chrome setup.  Is there a way to log out a user automatically 
after a set period of time?

 

Much obliged,

 

Bruckner de Villiers

083 625 1086

-- 
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/B80B7331-65D7-41DE-A22E-601A764E6A07%40gmail.com.


Re: Removing Hardcoded urls in Templates

2019-12-10 Thread Bruckner de Villiers
Thank you Daniel.

 

Bruckner de Villiers

083 625 1086

 

From:  on behalf of Daniel Hepper 

Reply to: 
Date: Tuesday, 10 December 2019 at 13:54
To: 
Subject: Re: Removing Hardcoded urls in Templates

 

It should be {% url 'polls:detail' question.id %}

 

I think you mixed up the steps "Removing hardcoded URLs in templates" and 
"Namespacing URL names"

 

Hope that helps,

Daniel

 

On Tue, Dec 10, 2019 at 11:58 AM Bruckner de Villiers 
 wrote:

Running Django 3.0 & Python 3.7.3.

 

Issue with Tutorial Part 3:
I replaced “{{ question.question_text 
}}” with
“{{ question.question_text 
}}” and get the following error:
Reverse for 'detail' not found. 'detail' is not a valid view function or 
pattern name.
{{ question.question_text 
}}
index.html:
{% if latest_question_list %}



{% for question in latest_question_list %}

{% comment %} {{ question.id }} 
{{ question.question_text }} {{ question.pub_date }} {% endcomment %}

{{ question.question_text 
}} {% comment %} - Why doesn't this work?-->  {% endcomment %}

{% endfor %}



{% else %}

No polls are available.

{% endif %}
urls.py:
from os import \

path

 

from django.urls import \

path

from . import \

views

 

app_name = 'polls'

urlpatterns = [

path('', views.index, name='index'),

path('/', views.detail, name='detail'),

path('/results/', views.results, name='results'),

path('/vote/', views.vote, name='vote'),

]
views.py:
from django.shortcuts import get_object_or_404, render

from django.http import \

HttpResponse

from django.shortcuts import \

render

#from django.template import loader

from .models import Question

 

# Create your views here.

def index(request):

latest_question_list = Question.objects.order_by('-pub_date')[:10]

context = {'latest_question_list': latest_question_list}

return render(request, 'polls/index.html', context)

 

def detail(request, question_id):

question = get_object_or_404(Question, pk=question_id)

return render(request, 'polls/detail.html', {'question': question})

 

def results(request, question_id):

response = "You're looking at the results of question %s."

return HttpResponse(response % question_id)

 

def vote(request, question_id):

return HttpResponse("You're voting on question %s." % question_id)

 
Much obliged,
 
 

 

Bruckner de Villiers

083 625 1086

-- 
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/0072F811-155B-41C2-BDCD-3C529150941B%40gmail.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/CAHEnUVW5AxWDmgRdvHEUYrd%3D%3D%2BFA6y4htqJjv9sJc-OkiCHQpA%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/641E4430-80FE-4BF0-9EEF-1CD0B1B2449B%40gmail.com.


Re: Removing Hardcoded urls in Templates

2019-12-10 Thread Bruckner de Villiers
Thank you Sencer.

 

 

Bruckner de Villiers

083 625 1086

 

From:  on behalf of Sencer Hamarat 

Reply to: 
Date: Tuesday, 10 December 2019 at 13:51
To: 
Subject: Re: Removing Hardcoded urls in Templates

 

Would you please replace url name with 'polls:detail', as described at 
https://docs.djangoproject.com/en/3.0/topics/http/urls/#id5

 


Saygılarımla,

Sencer HAMARAT

 

 

On Tue, Dec 10, 2019 at 1:58 PM Bruckner de Villiers 
 wrote:

Running Django 3.0 & Python 3.7.3.

 

Issue with Tutorial Part 3:
I replaced “{{ question.question_text 
}}” with
“{{ question.question_text 
}}” and get the following error:
Reverse for 'detail' not found. 'detail' is not a valid view function or 
pattern name.
{{ question.question_text 
}}
index.html:
{% if latest_question_list %}



{% for question in latest_question_list %}

{% comment %} {{ question.id }} 
{{ question.question_text }} {{ question.pub_date }} {% endcomment %}

{{ question.question_text 
}} {% comment %} - Why doesn't this work?-->  {% endcomment %}

{% endfor %}



{% else %}

No polls are available.

{% endif %}
urls.py:
from os import \

path

 

from django.urls import \

path

from . import \

views

 

app_name = 'polls'

urlpatterns = [

path('', views.index, name='index'),

path('/', views.detail, name='detail'),

path('/results/', views.results, name='results'),

path('/vote/', views.vote, name='vote'),

]
views.py:
from django.shortcuts import get_object_or_404, render

from django.http import \

HttpResponse

from django.shortcuts import \

render

#from django.template import loader

from .models import Question

 

# Create your views here.

def index(request):

latest_question_list = Question.objects.order_by('-pub_date')[:10]

context = {'latest_question_list': latest_question_list}

return render(request, 'polls/index.html', context)

 

def detail(request, question_id):

question = get_object_or_404(Question, pk=question_id)

return render(request, 'polls/detail.html', {'question': question})

 

def results(request, question_id):

response = "You're looking at the results of question %s."

return HttpResponse(response % question_id)

 

def vote(request, question_id):

return HttpResponse("You're voting on question %s." % question_id)

 
Much obliged,
 
 

 

Bruckner de Villiers

083 625 1086

-- 
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/0072F811-155B-41C2-BDCD-3C529150941B%40gmail.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/CACp8TZhfYfRH32oHh8Q4vFFWos9QoCXH2%3DrrjQCuxoOETjLc2A%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/56E2FE35-0C16-487C-ACE7-5D5ECDF13583%40gmail.com.


Removing Hardcoded urls in Templates

2019-12-10 Thread Bruckner de Villiers
Running Django 3.0 & Python 3.7.3.

 

Issue with Tutorial Part 3:
I replaced “{{ question.question_text 
}}” with
“{{ question.question_text 
}}” and get the following error:
Reverse for 'detail' not found. 'detail' is not a valid view function or 
pattern name.
{{ question.question_text 
}}
index.html:
{% if latest_question_list %}

    

    {% for question in latest_question_list %}

    {% comment %} {{ question.id }} 
{{ question.question_text }} {{ question.pub_date }} {% endcomment %}

    {{ question.question_text 
}} {% comment %} - Why doesn't this work?-->  {% endcomment %}

    {% endfor %}

    

{% else %}

    No polls are available.

{% endif %}
urls.py:
from os import \

    path

 

from django.urls import \

    path

from . import \

    views

 

app_name = 'polls'

urlpatterns = [

    path('', views.index, name='index'),

    path('/', views.detail, name='detail'),

    path('/results/', views.results, name='results'),

    path('/vote/', views.vote, name='vote'),

]
views.py:
from django.shortcuts import get_object_or_404, render

from django.http import \

    HttpResponse

from django.shortcuts import \

    render

#from django.template import loader

from .models import Question

 

# Create your views here.

def index(request):

    latest_question_list = Question.objects.order_by('-pub_date')[:10]

    context = {'latest_question_list': latest_question_list}

    return render(request, 'polls/index.html', context)

 

def detail(request, question_id):

    question = get_object_or_404(Question, pk=question_id)

    return render(request, 'polls/detail.html', {'question': question})

 

def results(request, question_id):

    response = "You're looking at the results of question %s."

    return HttpResponse(response % question_id)

 

def vote(request, question_id):

    return HttpResponse("You're voting on question %s." % question_id)

 
Much obliged,
 
 

 

Bruckner de Villiers

083 625 1086

-- 
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/0072F811-155B-41C2-BDCD-3C529150941B%40gmail.com.


Re: Difficulty with Tutorial Part 2

2019-12-09 Thread Bruckner de Villiers
Thank you Daniel. I believe that issue started with VSCode automatically 
inserting “from date time import date time” after I hit enter on “import date 
time”.

Thank you for the quick response. 

Bruckner
0836251086

> On 09 Dec 2019, at 10:38, Daniel Hepper  wrote:
> 
> 
> You can fix your code by changing datetime.timedelta to timedelta:
> 
> def was_published_recently(self):
> 
> return self.pub_date >= timezone.now() - timedelta(days=1)
> 
> 
> The statement "from datetime import datetime, timedelta" imports the classes 
> datetime and timedelta from the module datetime.
> 
> If you prefer to use "datetime.timedelta", you would have to use "import 
> datetime" instead of "from datetime import datetime, timedelta"
> 
> Hope that helps,
> Daniel
> 
>> On Mon, Dec 9, 2019 at 9:24 AM Bruckner de Villiers  
>> wrote:
>> Running Django 3.0 & Python 3.7.3
>> 
>> Everything works per the tutorial until I get to:
>> 
>> q.was_published_recently()
>> 
>> It throws the following error:
>> 
>> File 
>> "/Volumes/Data/DevelopmentTraining/django_tutorials/mysite/polls/models.py", 
>> line 19, in was_published_recently
>> 
>> return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
>> 
>> AttributeError: type object 'datetime.datetime' has no attribute 'timedelta'
>> 
>>  
>> 
>> I also tried importing timedelta from datetime – to no avail.
>> 
>>  
>> 
>> models.py code below:
>> 
>>  
>> 
>> import datetime
>> 
>> from datetime import datetime, timedelta
>> 
>>  
>> 
>> from django.db import \
>> 
>> models
>> 
>>  
>> 
>> from django.utils import timezone
>> 
>>  
>> 
>> # Create your models here.
>> 
>>  
>> 
>> class Question(models.Model):
>> 
>> question_text = models.CharField(max_length=200)
>> 
>> pub_date = models.DateTimeField('date published')
>> 
>>  
>> 
>> def __str__(self):
>> 
>> return self.question_text
>> 
>>  
>> 
>> def was_published_recently(self):
>> 
>> return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
>> 
>>  
>> 
>> class Choice(models.Model):
>> 
>> question = models.ForeignKey(Question, on_delete=models.CASCADE)
>> 
>> choice_text = models.CharField(max_length=200)
>> 
>> votes = models.IntegerField(default=0)
>> 
>>  
>> 
>> def __str__(self):
>> 
>> return self.choice_text
>> 
>>  
>> 
>>  
>> 
>> Much obliged,
>> 
>>  
>> 
>> Bruckner de Villiers
>> 
>> +27 (0)83 625 1086
>> 
>> -- 
>> 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/VI1PR07MB5680C26D410997944FF9A20BC8580%40VI1PR07MB5680.eurprd07.prod.outlook.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/CAHEnUVXhx5C%2BwhvAoBzOq4s_SXMxqzhq_7Y5k5fCmmhEqr%2B75Q%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/07F65819-A66D-4F0B-BCBB-97EB1F1AD02C%40gmail.com.


Difficulty with Tutorial Part 2

2019-12-09 Thread Bruckner de Villiers
Running Django 3.0 & Python 3.7.3

Everything works per the tutorial until I get to:

q.was_published_recently()

It throws the following error:

File 
"/Volumes/Data/DevelopmentTraining/django_tutorials/mysite/polls/models.py", 
line 19, in was_published_recently

    return self.pub_date >= timezone.now() - datetime.timedelta(days=1)

AttributeError: type object 'datetime.datetime' has no attribute 'timedelta'

 

I also tried importing timedelta from datetime – to no avail.

 

models.py code below:

 

import datetime

from datetime import datetime, timedelta

 

from django.db import \

    models

 

from django.utils import timezone

 

# Create your models here.

 

class Question(models.Model):

    question_text = models.CharField(max_length=200)

    pub_date = models.DateTimeField('date published')

 

    def __str__(self):

    return self.question_text

 

    def was_published_recently(self):

    return self.pub_date >= timezone.now() - datetime.timedelta(days=1)

 

class Choice(models.Model):

    question = models.ForeignKey(Question, on_delete=models.CASCADE)

    choice_text = models.CharField(max_length=200)

    votes = models.IntegerField(default=0)

 

    def __str__(self):

    return self.choice_text

 

 

Much obliged,

 

Bruckner de Villiers

+27 (0)83 625 1086

-- 
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/VI1PR07MB5680C26D410997944FF9A20BC8580%40VI1PR07MB5680.eurprd07.prod.outlook.com.


Re: Why is the Django server running even when pytlinter shows that there's some bug in the code?

2019-12-04 Thread Bruckner de Villiers
Which tutorial are you following?  Is it any good?

 

Bruckner de Villiers

083 625 1086

 

From:  on behalf of Aaryan Dewan 

Reply to: 
Date: Tuesday, 03 December 2019 at 16:52
To: Django users 
Subject: Re: Why is the Django server running even when pytlinter shows that 
there's some bug in the code?

 

Thanks! :)

On Tuesday, December 3, 2019 at 7:00:18 PM UTC+5:30, Bruckner de Villiers wrote:

I had the same issue and after trying various weird solutions on Stackoverflow, 
none of which worked, I found this simple solution – add this comment code to 
each line giving the error and it magically disappears:

 

# pylint: disable=no-member

 

 

Bruckner de Villiers

083 625 1086

 

From:  on behalf of Aaryan Dewan 

Reply to: 
Date: Tuesday, 03 December 2019 at 14:34
To: Django users 
Subject: Why is the Django server running even when pytlinter shows that 
there's some bug in the code?

 

I was just following this tutorial, on how to make Django apps and how to 
display a database to the user. I created a simple database in models.py and 
then, I defined a function in views.py, which used Item.objects.all(). Now 
Pylinter says that 'Item' has no 'objects' member!

So this should prevent the server from running ( as its a bug after all!), but 
if I type in python manage.py runserver, the terminal shows no error and the 
server starts functioning. 

 

Please see the photo attachment to get a clearer view of 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...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6428642e-3d7d-4d95-b387-0894c8410897%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/29ca61e2-640f-4e9e-8264-0bb691d0729c%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/02691AA0-A6E1-4A40-8EEF-8BC16196C72A%40gmail.com.


Re: Why is the Django server running even when pytlinter shows that there's some bug in the code?

2019-12-03 Thread Bruckner de Villiers
I had the same issue and after trying various weird solutions on Stackoverflow, 
none of which worked, I found this simple solution – add this comment code to 
each line giving the error and it magically disappears:

 

# pylint: disable=no-member

 

 

Bruckner de Villiers

083 625 1086

 

From:  on behalf of Aaryan Dewan 

Reply to: 
Date: Tuesday, 03 December 2019 at 14:34
To: Django users 
Subject: Why is the Django server running even when pytlinter shows that 
there's some bug in the code?

 

I was just following this tutorial, on how to make Django apps and how to 
display a database to the user. I created a simple database in models.py and 
then, I defined a function in views.py, which used Item.objects.all(). Now 
Pylinter says that 'Item' has no 'objects' member!

So this should prevent the server from running ( as its a bug after all!), but 
if I type in python manage.py runserver, the terminal shows no error and the 
server starts functioning. 

 

Please see the photo attachment to get a clearer view of 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/6428642e-3d7d-4d95-b387-0894c8410897%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/AA2D925E-0996-4647-B984-997BAF0FE9E2%40gmail.com.


Re: pass parameter from one class view to another

2019-11-05 Thread Bruckner de Villiers
I assume that you want to access the DetailView form the ListView??

To do that your List View template (which should be shop_list.html) should 
contain {{field}} – {{field}}

I don’t see your models.py so don’t know what the fields are, but here is an 
example of my code for a model called Organisation:

 

{% extends 'pbs1/pbs1_base.html' %}

{% block body_block %}



Available Organisations - 

Click for further details





{% for org in organisation_list %}

{{org.org_Name}} - 
{{org.org_HQ_Location}}

{% endfor %}







Back



{% endblock %}

 

So, when the user clicks on an organisation in the list it takes her to the 
DetailView of that organisation, by virtue of the line in the urls.py:

path('/', views.Org_DetailView.as_view(), name='detail'),

 

Caveat – I am still an novice, but this works for me.

 

Bruckner de Villiers

083 625 1086

 

From:  on behalf of sotiris moustogiannis 

Reply to: 
Date: Monday, 04 November 2019 at 02:09
To: Django users 
Subject: pass parameter from one class view to another

 

I have this listview and the context['datetimelist'] which is a list into def 
get_context_data

 

class ShopListView(ListView):

  model = Shops

  context_object_name= 'shops'

 

  template_name = 'booking/search.html'

 

  def get_context_data(self, **kwargs):

    context = super(ShopListView, self).get_context_data(**kwargs)

    query = self.request.GET.get('q')

    query1 = self.request.GET.get('q1')

    query2 = self.request.GET.get('q2')

    query3 = self.request.GET.get('q3')

    context['datetimelist'] = [query,query1,query2,query3]

    return context

 

 

  def get_queryset(self):

    query = self.request.GET.get('q')

    query1 = self.request.GET.get('q1')

    query2 = self.request.GET.get('q2')

    query3 = self.request.GET.get('q3')

    result_list = Shops.objects.exclude(Q(appointments__time=query) & 
Q(appointments__date = query1))

    result_list2 = Shops.objects.filter(Q(city=query2) & 
Q(typesport=query3))

    context = list(chain(result_list & result_list2))

    return context

 

And i want to pass this list to ShopDetailView class based view 

 

class ShopDetailView(DetailView):

 

  model = Shops

  

  template_name = 'booking/results.html'

 

 

  context_object_name= 'shops'

 

Also, here are my urls that calls these classes

 

path('search/', 
booking_views.ShopListView.as_view(template_name='booking/search.html'), 
name='search'),

path('results//', 
booking_views.ShopDetailView.as_view(template_name='booking/results.html'), 
name='results'),



How can i pass this list from one class based view to the other

-- 
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/5c011fa8-daa1-41ad-b4e8-b4bb7e8aa5d2%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/B2955F71-3B1D-4235-B224-65C30D97781D%40gmail.com.


Re:

2019-11-05 Thread Bruckner de Villiers
Udemy has a good course leading up to this topic – Python and Django Full Stack 
Web Development, still based on Django 1.x, but Django 2.x code is incuded.

Regards,

 

Bruckner de Villiers

083 625 1086

 

From:  on behalf of Paras Jain 

Reply to: 
Date: Tuesday, 05 November 2019 at 07:41
To: 

 

please somebody tell me what steps should i follow please need help 





Create a Django Web App called “Profile Storer” where a company can sign up 
using Email.

 

Once signed up, he can add more people to his team. Every team member can be 
either “Normal” type or “Manager” type. When you add a team member, that 
particular person gets an email with password, which he/she can use to login.

 

When a Manager type user logs in, he sees a list of all users of that company, 
he can go and edit any of the profile.

 

When a Normal user logs in, he sees only his own profile that he can edit.

 

Questions in Profile:

Name, Phone, Gender, Hobbies, Profile Picture.

-- 
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/CAMtmBS-mWtcx1Z0QFdvDc9F-ApoqHdP_9CkpaQzZUULow%3DHrFg%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/A168CEEC-75C0-44DB-8019-5B90ED826344%40gmail.com.


Re: Field Select MasterDetail

2019-10-31 Thread Bruckner de Villiers
I have a similar challenge and I think that I shall tackle it by making the 
first level dependency outside the main model, i.e. Building should be a 
ForeignKey in BuildingOwner model.  Then your main model shouldn’t have the a 
link to the Building model, but rather 2 ForeignKeys to BuildingOwner. Seems 
logical, but will it work?

Bruckner
0836251086

> On 01 Nov 2019, at 00:54, J-23  wrote:
> 
> 
> Hello,
> I am new to Django. I have a FormFault model, which has two foreign keys 
> "BuildingOwner" and "Building", the key "Building" depends on "BuildingOwner" 
> on the form, it gives me two fields of type Select (ComboBox) or is there a 
> way in Django that the content of ComboBox changes depending on 
> "BuildingOwner" values?
> 
> from django.db import models
> 
> class Items(models.Model):
> Item_Text = models.CharField("Temat", max_length=100)
> 
> def __str__(self):
> return self.Item_Text
> 
> 
> class Meta:
>  verbose_name = "Temat zgłoszenia"
>  verbose_name_plural = "Temat zgłoszeń"
> 
> class DocumentType(models.Model):
> Document_Text = models.CharField("Rodzaj", max_length=100) 
> 
> def __str__(self):
> return self.Document_Text
> 
> class Meta:
> verbose_name = "Rodzaj zgłoszenia"
> verbose_name_plural = "Rodzaj zgłoszeń"
> 
> class Status(models.Model):
>Status_Text = models.CharField("Status", max_length=100)
> 
>def __str__(self):
>   return self.Status_Text
> 
>class Meta:
>   verbose_name = "Status zgłoszenia"
>   verbose_name_plural = "Status zgłoszeń"
> 
> class BuildingOwner(models.Model):
> BuildingOwner_Text = models.CharField("Właściciel", max_length=100)
> 
> def __str__(self):
>   return self.BuildingOwner_Text
> 
> class Meta:
>   verbose_name = "Właściciela budynku"
>   verbose_name_plural = "Właściciel budynków"
> 
> class Building(models.Model):
> BuildingOwner = models.ForeignKey(BuildingOwner, verbose_name="Właściciel 
> budynku", on_delete=models.CASCADE)
> Building_Text = models.CharField("Budynek", max_length=150)
>   
> def __str__(self):
>   return self.Building_Text
> 
> class Meta:
>   verbose_name = "Budynek"
>   verbose_name_plural = "Budynki"
> 
> class FormFault(models.Model):
> Person = models.CharField("Imię i Nazwisko",max_length=300)
> Email = models.EmailField("E-mail", max_length=50)
> Items = models.ForeignKey(Items, verbose_name="Temat", 
> on_delete=models.CASCADE)
> DocumentType = models.ForeignKey(DocumentType, verbose_name="Rodzaj 
> dokumentu", on_delete=models.CASCADE)
> Status = models.ForeignKey(Status, on_delete=models.CASCADE)
> BuildingOwner = models.ForeignKey(BuildingOwner, verbose_name="Właściciel 
> budynku", on_delete=models.CASCADE)
> Building = models.ForeignKey(Building, verbose_name="Budynek", 
> on_delete=models.CASCADE)
> Place = models.CharField("Lokal", max_length=10)
> 
> class Meta:
>  verbose_name = "Zgłoszenie"
>  verbose_name_plural = "Zgłoszenia"
> 
> 
> 
> 
> 
> 
> I found a library here: 
> https://github.com/runekaagaard/django-admin-flexselect
> 
> but I'm wondering if this can't be done in a simpler way.
> 
> Best regards,
> -- 
> 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/1c2bd867-91b3-4434-9604-08eca8e7b8b1%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/1C1B35E1-7F5A-4D57-86ED-F0C6A2212758%40gmail.com.


Re: html home file is not opening while running under django env......

2019-10-31 Thread Bruckner de Villiers
Did you import include?

Bruckner
0836251086

> On 01 Nov 2019, at 00:29, হজমুলা খান  wrote:
> 
> 
> 
> 
>> On Thursday, October 31, 2019 at 12:22:48 PM UTC, Kasper Laudrup wrote:
>> Hi হজমুলা খান, 
>> 
>> On 31/10/2019 11.22, হজমুলা খান wrote: 
>> > i am novice and following django for beginners ebook. while i am running 
>> > the program  base.html and about.html are working properly but when i 
>> > click on the home link, it shows: 
>> > 
>> > 
>> >   Page not found (404) 
>> > 
>> > Request Method:GET 
>> > Request URL:http://localhost:8000/home 
>> > 
>> > Using the URLconf defined in |pages_project.urls|, Django tried these 
>> > URL patterns, in this order: 
>> > 
>> >  1. admin/ 
>> >  2. [name='home'] 
>> >  3. about/ [name='about'] 
>> > 
>> > The current path, |home|, didn't match any of these. 
>> > 
>> > 
>> > i have installed Jinja2 and if i open base.html without running django 
>> > server, it works well but under django server it's not working. what 
>> > should i do? 
>> > 
>> 
>> You need to add 'home' to your urls.py inside your pages_project 
>> directory. Read more here: 
>> 
>> https://docs.djangoproject.com/en/2.2/topics/http/urls/ 
>> 
>> Kind regards, 
>> 
>> Kasper Laudrup 
> 
> 
> thanx for your reply. i have edited pages_project/urls.py as follows: 
> urlpatterns = [ path('admin/', admin.site.urls), path('home/', 
> include('pages.urls')), in this case home page is working but base.html and 
> about.html is not showing . if i add path('about/', include('pages.urls')), 
> then both home.html and about.html is showing but the url becomes 
> localhost:8000/home/about. localhost:8000/about is not working. i put 
> home.html in new folder pages and the order your talked about but they have 
> no effect because i kept the files in both sides. plz share any new idea  
> -- 
> 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/83c8c6ed-0a81-47a3-9e51-bdf8458fb2bb%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/CA3EBFB3-410E-42F5-B3A3-114D0D7D3670%40gmail.com.


Re: Export HTML template filled by form to HTML file

2019-10-31 Thread Bruckner de Villiers
If I haven’t misunderstood, you wish to add/update/list data to/from the DB via 
a form?  I am learning myself and I have just successfully  managed to achieve 
this through CBV’s (Class Based Views), which obviate the use of forms and 
perform well – with fewer lines of code. In Django 2.2.x the views.py file 
contains the following import:

from django.views.generic import (

TemplateView,

View, ListView, DetailView, CreateView, UpdateView, DeleteView)

 

One of my models is called Organisation inside the application – pbs1/.  The 
views.py file contains the following classes:

class Org_View(ListView):

model = Organisation

# Returns organisation_list

 

class Org_DetailView(DetailView):

context_object_name = "org_detail"

model = Organisation

template_name = 'pbs1/organisation_detail.html'

# Returns organisation

 

class OrgCreateView(CreateView):

fields = ('org_Name', 'org_Site', 'org_HQ_Location', 'org_Sector',

  'currency_Code', 'org_Parent', 'org_Turnover', 
'org_Multi_National', 'spec_Name')

model = Organisation

 

class OrgUpdateView(UpdateView):

fields = ('org_Name', 'org_Site', 'org_HQ_Location', 'org_Sector',

  'currency_Code', 'org_Parent', 'org_Turnover', 
'org_Multi_National', 'spec_Name')

model=Organisation

 

class OrgDeleteView(DeleteView):

model = Organisation

success_url = reverse_lazy("pbs1:organisation_list")

 

Each class does exactly what it says – e.g. OrgUpdateView allows me to update a 
previously created record in the DB.  The urls.py and *.html are a bit more 
complicated.  But, I can share these with you as well.  I learnt/am learning 
this stuff through Python and Django Full Stack Web Developer Bootcamp from 
Udemy.

Regards,

Bruckner de Villiers

083 625 1086

 

From:  on behalf of Valentin Jungbluth 

Reply to: 
Date: Thursday, 31 October 2019 at 13:45
To: Django users 
Subject: Export HTML template filled by form to HTML file

 

I have a template page on which one I access when I filled my `Django form`. 
This page is a simple `HTML page` with data coming from my form. I would like 
to be able to download the filled template. That's to say, get a browser window 
which let to download the template or by clicking on a button which will save 
the HTML template somewhere.

 

This is my code in my **views.py** file:

 

   

 class TemplateGenerator(TemplateView):
''' This class displays the form and lets to save data into my database.
It redirects users to the filled HTML template '''
form_class = CommunicationForm
template_name = 'form.html'
success_url = '/HTML_Result/'

def get(self, request):
form = self.form_class()
return render(request, self.template_name, {'form': form})

def post(self, request):
form = self.form_class(request.POST, request.FILES)
if form.is_valid():
form.save()
return redirect('HTML_Result')
args = {'form': form}
return render(request, self.template_name, args)


class HTMLResult(TemplateView):
  ''' This class displays the template filled thanks to the form from 
TemplateGenerator() class '''
  template_name = 'template_1.html'

  def get(self, request):
  data = Communication.objects.values().latest('id')
  self.donwload_html()
  return render(request, self.template_name, {'data': data})

  def donwload_html(self):
  file_path = os.path.join(settings.MEDIA_ROOT, 'media')
  if os.path.exists(file_path):
  with open(file_path, 'rb') as fh:
  response = HttpResponse(fh.read(),

content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
  response['Content-Disposition'] = 'inline; filename=' + 'test'
  return response
  raise Http404

 

 

I know I need to use `Content-Disposition` in order to download the HTML page, 
but I don't find a way to use it correctly.
Do you have any idea ?

 

Thank you by 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/b2cc33dc-1af2-45d0-b8b5-c6b95267beff%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/4CF0FAC5-4173-4263-8810-9211D7E60E88%40gmail.com.