Friday, January 29, 2021

Re: multiplying two fields

data = Articles.objects.all().annotate(result=F('coust_buy') * F('quantity')).output_field=FloatField('result'),

contains a type for the field "cost_buy" (i.e. not "coust_by").

If that isn't it please give us the traceback.

On Fri, Jan 29, 2021 at 8:50 PM jose angel encinas ramos <encinasj.angel@gmail.com> wrote:
Guys gd evening

I need help,really i don't kwnow how to do a multiply two fields, have a model called Articles.

class Articles(models.Model):
#models article
Nuevo = 'Nuevo'
Semi_nuevo = 'Semi_nuevo'
Usado = 'Usado'
Otros = 'Otros'
STATE_ACTUAL = (
(Nuevo, 'Nuevo'),
(Semi_nuevo,'Semi_nuevo'),
(Usado,'Usado'),
(Otros,'Otros')
)
name = models.CharField(max_length=50)
quantity = models.PositiveIntegerField()
fk_brand = models.ForeignKey(Brand, null=True, on_delete=models.SET_NULL)
model = models.CharField(max_length=50)
fk_category = models.ForeignKey(Category, null=True, on_delete=models.SET_NULL)
cost_buy = models.DecimalField(max_digits=10, decimal_places=2)
fk_supplier = models.ForeignKey(Supplier, null=True, on_delete=models.SET_NULL)
userful_life = models.DateField()
actual_state = models.CharField(max_length=12, choices=STATE_ACTUAL)
date_check = models.DateField()
location = models.CharField(max_length=50)
img = models.ImageField(upload_to='articles', null=True, blank=True)
description = models.TextField(blank=True)
#actions
created = models.DateTimeField(auto_now_add=True)
update = models.DateTimeField(auto_now=True)

class Meta:
verbose_name = 'Article'
verbose_name_plural = 'Articles'

@property
def result(self,*args, **kwargs):
mult = self.cost_buy * self.quantity
return mult

class Meta:
verbose_name = 'Article'
verbose_name_plural = 'Articles'

def __str__(self):
return '{} {} {}'.format(self.name ,self.cost_buy, self.quantity)

so i want to multiply 2 filed , cost_buy * quantity and the result show in the template

i was to try did this query in view.py 
data = Articles.objects.all().annotate(result=F('coust_buy') * F('quantity')).output_field=FloatField('result')
 

but isn't work





--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3b573d77-b89a-4b39-95fd-dfd6f9d90910n%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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAA1Tdz39yC%3D571QyKye0__DWYw%3Deqb_mTcVuWenp2cLj-rX-bA%40mail.gmail.com.

multiplying two fields

Guys gd evening

I need help,really i don't kwnow how to do a multiply two fields, have a model called Articles.

class Articles(models.Model):
#models article
Nuevo = 'Nuevo'
Semi_nuevo = 'Semi_nuevo'
Usado = 'Usado'
Otros = 'Otros'
STATE_ACTUAL = (
(Nuevo, 'Nuevo'),
(Semi_nuevo,'Semi_nuevo'),
(Usado,'Usado'),
(Otros,'Otros')
)
name = models.CharField(max_length=50)
quantity = models.PositiveIntegerField()
fk_brand = models.ForeignKey(Brand, null=True, on_delete=models.SET_NULL)
model = models.CharField(max_length=50)
fk_category = models.ForeignKey(Category, null=True, on_delete=models.SET_NULL)
cost_buy = models.DecimalField(max_digits=10, decimal_places=2)
fk_supplier = models.ForeignKey(Supplier, null=True, on_delete=models.SET_NULL)
userful_life = models.DateField()
actual_state = models.CharField(max_length=12, choices=STATE_ACTUAL)
date_check = models.DateField()
location = models.CharField(max_length=50)
img = models.ImageField(upload_to='articles', null=True, blank=True)
description = models.TextField(blank=True)
#actions
created = models.DateTimeField(auto_now_add=True)
update = models.DateTimeField(auto_now=True)

class Meta:
verbose_name = 'Article'
verbose_name_plural = 'Articles'

@property
def result(self,*args, **kwargs):
mult = self.cost_buy * self.quantity
return mult

class Meta:
verbose_name = 'Article'
verbose_name_plural = 'Articles'

def __str__(self):
return '{} {} {}'.format(self.name ,self.cost_buy, self.quantity)

so i want to multiply 2 filed , cost_buy * quantity and the result show in the template

i was to try did this query in view.py 
data = Articles.objects.all().annotate(result=F('coust_buy') * F('quantity')).output_field=FloatField('result')
 

but isn't work





--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3b573d77-b89a-4b39-95fd-dfd6f9d90910n%40googlegroups.com.

Re: Static Folder not loading

On 29/01/2021 15.56, ule...@gmail.com wrote:
>
> try
> /./manage.py findstatic test.css/

The user is running Windows, so I doubt that would work.

Also, what makes you think this would make a difference?

The only thing this would change as far as I can tell is that the users
"python" command is an alias to "python2" while Django requires Python
3. Do you think this is related to the Python version?

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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5477b65a-a2af-b1e1-243a-a1fe34095266%40stacktrace.dk.

Re: win error 10013

On 29/01/2021 05.30, Xorox Chalise wrote:
> System check identified no issues (0 silenced).
> January 29, 2021 - 10:09:36
> Django version 3.1.5, using settings 'lecture3.settings'
> Starting development server at http://127.0.0.1:8000/
> Quit the server with CTRL-BREAK.
> Error: [WinError 10013] An attempt was made to access a socket in a way
> forbidden by its access permissions
>
> #what should I do to deal with this error please help
>

You most likely have some kind of "security software" (ie. snakeoil)
running. Try to disable that and see if that helps.

Otherwise you have to look into the permissions for your current user,
but that requires help from someone experienced with Windows which is
not me.

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+unsubscribe@googlegroups.com
> <mailto:django-users+unsubscribe@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/27df69ad-c3a3-4917-bc61-d731b963f2b8n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/27df69ad-c3a3-4917-bc61-d731b963f2b8n%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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1d10ef46-3897-fbb0-72ed-12e36f81b5e6%40stacktrace.dk.

How to programmatically set the model when using Django CreateView?

I am trying to programmatically set the model for a Django class-based view that inherits from CreateView and displays a form for creating a 'member' object. My problem is that  my template is not displaying the form itself. Note that I override the 'get' method to determine what model the view should use. The template page renders and I see the submit button but when I view the page's source code, the form is missing. Here's my code:

    # urls.py
    path('profile/create/', views.ProfileCreate.as_view(), name='profile-create'),

    # views.py
    class ProfileCreate(CreateView):
        model = None
        template_name = None

        def get(self, request, *args, **kwargs):
            member = Member.objects.get(user=request.user)
            if member.is_couple:
                self.model = ProfileCouple
                self.template_name = 'account/profile_couple_create.html'
                self.fields = ['person1_name', 'person2_name',
                               'person1_dob', 'person2_dob']
            else:
                self.model = ProfileSingle
                self.template_name = 'account/profile_single_create.html'
                self.fields = ['person1_name', 'person1_dob']

            context = {}
            return render(request, self.template_name, context)

    # models.py
    class ProfileSingle(models.Model):
        user = models.OneToOneField(User, on_delete=models.CASCADE, null=True)
        person1_name = models.CharField(_("Name"), max_length=50)
        person1_dob = models.DateField()

        def __str__(self):
            return self.user.username

    class ProfileCouple(models.Model):
        user = models.OneToOneField(User, on_delete=models.CASCADE, null=True)
        person1_name = models.CharField(_("Name 1"), max_length=50)
        person1_dob = models.DateField()
        person2_name = models.CharField(_("Name 2"), max_length=50)
        person2_dob = models.DateField()

        def __str__(self):
            return self.user.username

    # forms.py
    class CreateSingleProfileForm(forms.ModelForm):
        class Meta:
            model = ProfileSingle
            fields = ('user', 'person1_name', 'person1_dob')
            labels = {'user': _('Username'), 'person1_name': _(
                'Person 1 Name'), 'person1_dob': _('Person 1 DOB')}
    
    class CreateCoupleProfileForm(forms.ModelForm):
        class Meta:
            model = ProfileCouple
            ...

    # profile_single_create.html
    <div class="container mt-4">
      <h1>Create Your Profile</h1>
      <form method="post">{% csrf_token %}
          {{ form.as_p }}
          <input type="submit" value="Save">
      </form>
    </div>

    # profile_couple_create.html
    (Code similar to single template)

I know that with CBVs, Django will build the form for me.  But there will be times when I need to customize the form as I do here. What am I missing?

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6d394628-6132-4927-8324-466347c8c427n%40googlegroups.com.

Re: Django Microsoft Authentication Backend not succeeding on new deployments

On Sat, Jan 23, 2021 at 7:41 PM Ryan Nowakowski <ryan@fattuba.com> wrote:
>
> On Sat, Jan 23, 2021 at 11:05:14AM -0800, Larry Martell wrote:
> > On Sat, Jan 23, 2021 at 8:14 AM Ryan Nowakowski <tubaman@fattuba.com> wrote:
> > >
> > > A couple of places to look:
> > >
> > > 1. Different domains on the new boxes? You'll need to add the new callback urls on the Microsoft side.
> > > 2. Different version of Python on the new boxes?
> >
> > Same domain name, same version of python and all python packages.
> > There are some minor revision differences in a bunch of OS level
> > packages. Could that be a factor?
> >
>
> Did you create your virtualenv with --system-site-packages? If not then
> I don't think the OS packages will be a factor.

We finally found the issue - I said we had the same version of all the
python packages but we did not - the new system had 2.0.1 version of
pyjwt. When we downgraded to 1.7.1 it started working again. The
requirements file for Django Microsoft Authentication Backend have
pyjwt [required: Any]

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACwCsY4d_%3D3Q660gF%3DtrcAQmj7bkG%2BMnXaYf%3DgCt8WH0UnCkjg%40mail.gmail.com.

Re: Static Folder not loading


try
./manage.py findstatic test.css
Op vrijdag 29 januari 2021 om 15:52:44 UTC+1 schreef fcip...@gmail.com:
I'm sending from my phone so it won't have markdown.

It looks like your not defining all of them properly. Put a static folder you'll manually in trydjango/trydjango. This will be where Staticfiles_dirs gathers the files. Then static_root will be where is collectstatic will store them. Static_URL is important as it will be the file name target it will look for when running collectstatic.

Try:

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'trydjango/static')



Best Regards,
Frank Cipolone


On Jan 29, 2021, at 6:23 AM, hari49pf <hari...@gmail.com> wrote:


<Screenshot_2021-01-29_16-48-54(django_settings).png>


above is a screenshot and path for the static folder. 
On Friday, January 29, 2021 at 3:05:06 AM UTC+5:30 fcip...@gmail.com wrote:
Whats your STATIC_DIRS, STATIC_PATH, and STATIC_URL and what it the tree to the folder your static is in?

> On Jan 28, 2021, at 1:26 PM, hari49pf <hari...@gmail.com> wrote:
>
> Yes, i did it created a folder with css & other files, but no use.
>
> On 28/01/21 11:49 pm, Larry Martell wrote:
>> On Thu, Jan 28, 2021 at 10:16 AM hari49pf <hari...@gmail.com> wrote:
>>> Hi,
>>>
>>> I am trying to load static file to my project its not loading,
>>> I have changed the path of static in settting.py still its not loading static file.
>>> tryed to check the file is loading by using
>>> manage.py findstatic test.css
>>> PLZ help
>> Have you run collectstatic?
>>
>
> --
> 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...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/928aaad3-3f02-45e4-91fa-d3a56da673db%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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ceb2424c-870d-4467-a29a-7337d0471283n%40googlegroups.com.
<Screenshot_2021-01-29_16-48-54(django_settings).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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/91c26895-d347-4bef-a62e-7b37d712bbe1n%40googlegroups.com.