Re: How to make a Purchase Order app?

2018-08-03 Thread Andréas Kühne
Hi,

I think you are doing it right. I would remove the PurchaseOrderTotal model
however. The reason for this is that the purchase order itself should know
it's total and so on. Either you can add a signal on the save of the
PurchaseOrderItem - and update the PurchaseOrder total or the PurchaseOrder
could calculate the total when required via a method.

I think the easiest way would be to add a method that calculates the total:

@property
def subtotal(self):
order_total = 0
for item in self.purchaseorderitem_set.all():
order_total += item.qty * item.unit_price
return order_total

Now it is a property on the purchase order. So calling:
purchase_order.subtotal will get the total for the purchase order.

2 other things:
1. You can remove the amount in the PurchaseOrderItem and calculate the
total for the row when required (see my example above) - this of course
depends on WHEN you want to show the total. The same thing goes for
calculating the total on the PurchaseOrder. You could add a property the
same way I did for the PurchaseOrder in the PurchaseOrderItem class.
2. The names you have given your properties that are foreign keys are not
that good from an object oriented perspective. I would for example call the
invoice_number field on the PurchaseOrder as "invoice". The same goes for
the po_number_fk fields. Because when you assign them or when you want to
get a value from the invoice it would be easier to read -
purchase_order.invoice.id than purchase_order.invoice_number.id.

Hope that helps somewhat.

If you don't want to calculate the total each time (it all depends on the
usage), you can use signals to see when a model is saved/created and then
update the subtotal in the PurchaseOrder. See here for information about
signals: https://docs.djangoproject.com/en/2.0/topics/signals/

Andréas

2018-08-02 19:27 GMT+02:00 Alexander Joseph :

> I've been working on a Purchase Order app but I'm getting a little
> confused how I'm going to put it all together.
>
> I have 3 models -
>
> class PurchaseOrder(models.Model):
> po_number = models.IntegerField(default=get_po_number, unique=True)
> po_date = models.DateField()
> invoice_number = models.ForeignKey(Invoice, on_delete=models.CASCADE)
> 
>
>
> class PurchaseOrderItem(models.Model):
> po_number_fk = models.ForeignKey(PurchaseOrder,
> on_delete=models.CASCADE)
> qty = models.IntegerField()
> unit = models.CharField(max_length=100, blank=True, null=True)
> description = models.CharField(max_length=255)
> unit_price = models.DecimalField(max_digits=6, decimal_places=2)
> amount = models.DecimalField(max_digits=6, decimal_places=2)
>
>
> class PurchaseOrderTotal(models.Model):
> po_number_fk = models.ForeignKey(PurchaseOrder,
> on_delete=models.CASCADE)
> subtotal = models.DecimalField(max_digits=6, decimal_places=2)
> tax = models.DecimalField(max_digits=6, decimal_places=2,
> default="7.82")
> shipping = models.DecimalField(max_digits=6, decimal_places=2)
> other = models.DecimalField(max_digits=6, decimal_places=2)
> total = models.DecimalField(max_digits=6, decimal_places=2)
>
>
> the first (PurchaseOrder) holds information about the purchase order
> itself. ie. what the invoice number is, the vendor, etc.
> the second (PurchaseOrderItem) lists items in the purchase order to
> purchase
> the third (PurchaseOrderTotal) totals up the amounts from the items and
> adds tax etc. (I may not need this model.. I can probably put this info in
> the first model?)
>
>
> Does it look like I'm going about this in the right way or should I take
> away the third model and put those fields from the third model into the
> first model? How do I total up all prices for all items? I'm sure I'll need
> to do some sort of loop to total up all prices but where do I do that? In
> the form_valid fucntion? or do I override the save function and do it
> there? 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/dc6a1cb9-0770-49d9-9c89-92d1f947e718%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at

Re: CI build failing but local builds pass

2018-08-03 Thread Ismail Sunni
Thanks so much. I got this problem also.

On Thursday, August 2, 2018 at 2:02:34 AM UTC+7, Ajat Prabha wrote:
>
> The issue is fixed now, it happened because Travis used PostgreSQL v9.2 by 
> default and Django v2.1 works with v9.4+ (changelog 
> 
> )
>
> On Wednesday, 1 August 2018 23:47:16 UTC+5:30, Ajat Prabha wrote:
>>
>> Hi,
>> I'm working on a hobby project  
>> and the issue I'm facing is that the CI build 
>>  is failing 
>> and I'm not sure why is this happening.
>> The only difference is that I updated 
>>  Django to v2.1 
>> after the last successful build. However, when I try to make migrations and 
>> migrate on my local machine, it runs smoothly.
>>
>> Here's the log:
>>
>> python3 manage.py migrate
>> /home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/psycopg2/__init__.py:144:
>>  UserWarning: The psycopg2 wheel package will be renamed from release 2.8; 
>> in order to keep installing from binary please use "pip install 
>> psycopg2-binary" instead. For details see: 
>> .
>>   """)
>> Operations to perform:
>>   Apply all migrations: accounts, admin, auth, contenttypes, courses, 
>> sessions, social_django, study_material
>> Running migrations:
>>   Applying accounts.0001_initial... OK
>>   Applying courses.0001_initial... OK
>>   Applying contenttypes.0001_initial... OK
>>   Applying auth.0001_initial... OK
>>   Applying accounts.0002_auto_20180801_1737... OK
>>   Applying admin.0001_initial... OK
>>   Applying admin.0002_logentry_remove_auto_add... OK
>>   Applying admin.0003_logentry_add_action_flag_choices... OK
>>   Applying contenttypes.0002_remove_content_type_name... OK
>>   Applying auth.0002_alter_permission_name_max_length... OK
>>   Applying auth.0003_alter_user_email_max_length... OK
>>   Applying auth.0004_alter_user_username_opts... OK
>>   Applying auth.0005_alter_user_last_login_null... OK
>>   Applying auth.0006_require_contenttypes_0002... OK
>>   Applying auth.0007_alter_validators_add_error_messages... OK
>>   Applying auth.0008_alter_user_username_max_length... OK
>>   Applying auth.0009_alter_user_last_name_max_length... OK
>>   Applying sessions.0001_initial... OK
>>   Applying social_django.0001_initial... OK
>>   Applying social_django.0002_add_related_name...Traceback (most recent call 
>> last):
>>   File 
>> "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/db/backends/utils.py",
>>  line 85, in _execute
>> return self.cursor.execute(sql, params)
>> psycopg2.ProgrammingError: syntax error at or near "WITH ORDINALITY"
>> LINE 6: FROM unnest(c.conkey) WITH ORDINALITY co...
>>   ^
>> The above exception was the direct cause of the following exception:
>> Traceback (most recent call last):
>>   File "manage.py", line 15, in 
>> execute_from_command_line(sys.argv)
>>   File 
>> "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/core/management/__init__.py",
>>  line 381, in execute_from_command_line
>> utility.execute()
>>   File 
>> "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/core/management/__init__.py",
>>  line 375, in execute
>> self.fetch_command(subcommand).run_from_argv(self.argv)
>>   File 
>> "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/core/management/base.py",
>>  line 316, in run_from_argv
>> self.execute(*args, **cmd_options)
>>   File 
>> "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/core/management/base.py",
>>  line 353, in execute
>> output = self.handle(*args, **options)
>>   File 
>> "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/core/management/base.py",
>>  line 83, in wrapped
>> res = handle_func(*args, **kwargs)
>>   File 
>> "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/core/management/commands/migrate.py",
>>  line 203, in handle
>> fake_initial=fake_initial,
>>   File 
>> "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/db/migrations/executor.py",
>>  line 117, in migrate
>> state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, 
>> fake_initial=fake_initial)
>>   File 
>> "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/db/migrations/executor.py",
>>  line 147, in _migrate_all_forwards
>> state = self.apply_migration(state, migration, fake=fake, 
>> fake_initial=fake_initial)
>>   File 
>> "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/db/migrations/executor.py",
>>  line 244, in apply_migration
>> state = migration.apply(state, schema_editor)
>>   File 
>> 

Django dynamic Database

2018-08-03 Thread Cheran Rj
Hi! how to create dynamic database for each user or organisation 

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3188932a-9f8d-4716-9496-6a11bc87d6cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Do some task using models in a view before a request is executed.

2018-08-03 Thread Christian
Thanks!

Am Donnerstag, 2. August 2018 15:18:36 UTC+2 schrieb Jason:
>
> DRF viewsets provide default implementations of list (GET resource/) and 
> retrieve (GET resource/id).  You can just reimplement those methods and 
> call `rfm_update` in them.
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/71c96736-ffa8-4f1e-b627-551d41a63b09%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: GEOSGeometry function dies with error pure virtual method called message

2018-08-03 Thread Tim Graham
The code you gave doesn't crash on my system, even with Django 2.0.x. Can 
you give a complete traceback?

On Thursday, August 2, 2018 at 12:15:52 PM UTC-4, Saurabh Khanduja wrote:
>
> The version of django is 2.0.4
> Debugging - Just step into code where the program is crashing in transform 
> function in file 
> ~/anaconda3/envs/py35/lib/python3.5/site-packages/django/contrib/gis/geos/geometry.py
>
> On Thursday, 2 August 2018 16:28:43 UTC+2, Tim Graham wrote:
>>
>> I'm not sure what you mean by "On debugging". Is that the complete code 
>> snippet to reproduce the issue? I don't see a crash on my system. Which 
>> Django version?
>>
>> On Thursday, August 2, 2018 at 8:29:51 AM UTC-4, Saurabh Khanduja wrote:
>>>
>>> Hi,
>>>  This is the piece of code I am working with:-
>>>
>>> poly = GEOSGeometry('Polygon((-951499 -1276279, '
>>>  '-951498 -1276279, '
>>>  '-951498 -1276278, '
>>>  '-951499 -1276278,'
>>>  '-951499 -1276279))', srid=5514).transform(4326)
>>>
>>> On debugging, the file geometry.py it crashes on line 475:-
>>>
>>> capi.destroy_geom(self.ptr)
>>>
>>> I updated my gdal from 1.11.3 to 2.1.3, but still stuck with the same 
>>> error.
>>>
>>> For, now, I am passing clone=True to workaround this issue, but would 
>>> like to know if there is a mistake on my part or report it if it is a bug.
>>>
>>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0432fee4-81e7-4eb2-ba4a-44d6234f9f6b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


JSON serializable error

2018-08-03 Thread Anusha Kommineni
Hi,
I am getting below error.Can anyone help me?


TypeError: datetime.datetime(2018, 2, 12, 0, 0, tzinfo=) is not JSON
serializable

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACBpiKjjH6WhtHfc%3DqLzQ7v5Dc7jDNuAmkRnzB4kb9rzE_Rr1Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django keeps object references in case of exception

2018-08-03 Thread claudio . cilloni
Hi all.

I know Python but I'm pretty new to Django. It seems to me this is a bug, 
but I'd like your opinions before actually filing a bug report.

this is my function, executed by an http call:

@csrf_exempt
def main(request):

obj = MyClass()
# raise AssertionError

return HttpResponse('OK\n', content_type='text/plain')


this is MyClass:

class MyClass:

def __init__(self):
pass

def __del__(self) :
print('> DEL')


without raising the AssertionError, everything works fine and I see the 
print() output in the server log as soon the function main() terminates.
But uncommenting the raise line I don't see the print() output; triggering 
the server reload by saving a source file, the print() output shows up.

This happens with the internal webserver as well as with Lighttpd + 
Gunicorn.

I think Django is keeping some reference to the frame object of the 
function main(). This behaviour doesn't let me to close things like file 
descriptors or sockets in case of untrapped exception.

Is this a bug? Or... what I'm doing wrong?

I'm running Django 2.0.7, Python 3.6.1, Linux.
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/cccaaf31-1958-415a-831f-ef3ad0150399%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: JSON serializable error

2018-08-03 Thread Julio Biason
Hi Anusha,

It seems you're trying to generate a JSON of some object/dictionary with a
Datetime in it. Datetimes are not serializable 'cause there is no date/time
representation in JSON (maybe epoch, but that's not the default).

On Fri, Aug 3, 2018 at 11:18 AM, Anusha Kommineni <
anushakommineni...@gmail.com> wrote:

> Hi,
> I am getting below error.Can anyone help me?
>
>
> TypeError: datetime.datetime(2018, 2, 12, 0, 0, tzinfo=) is not JSON
> serializable
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CACBpiKjjH6WhtHfc%3DqLzQ7v5Dc7jDNuAmkRnzB4kb9rzE
> _Rr1Q%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Julio Biason*, Sofware Engineer
*AZION*  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101   |  Mobile: +55 51
*99907 0554*

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEM7gE0KV4kLbOnb2Eeinohpa%3D_F3MmF7cuo%2BH0N_gYKxG_78g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: JSON serializable error

2018-08-03 Thread vineeth sagar
You can use unix timestamp, It's json serializable and can be converted to
a datetime object. If I am not wrong you were trying to store it in a
session? try this.

import time

timestamp=time.time()
request.session['current time']= timestamp
import datetime

datetime.datetime.fromtimestamp(request.session['current time'])

On Fri, Aug 3, 2018 at 7:56 PM, Julio Biason  wrote:

> Hi Anusha,
>
> It seems you're trying to generate a JSON of some object/dictionary with a
> Datetime in it. Datetimes are not serializable 'cause there is no date/time
> representation in JSON (maybe epoch, but that's not the default).
>
> On Fri, Aug 3, 2018 at 11:18 AM, Anusha Kommineni <
> anushakommineni...@gmail.com> wrote:
>
>> Hi,
>> I am getting below error.Can anyone help me?
>>
>>
>> TypeError: datetime.datetime(2018, 2, 12, 0, 0, tzinfo=) is not JSON
>> serializable
>>
>> --
>> 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 post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/CACBpiKjjH6WhtHfc%3DqLzQ7v5Dc7jDNuAmkRnzB4k
>> b9rzE_Rr1Q%40mail.gmail.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> *Julio Biason*, Sofware Engineer
> *AZION*  |  Deliver. Accelerate. Protect.
> Office: +55 51 3083 8101   |  Mobile: +55 51
> *99907 0554*
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAEM7gE0KV4kLbOnb2Eeinohpa%3D_
> F3MmF7cuo%2BH0N_gYKxG_78g%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMMZq8PcK1Eh7%2B_jR%3DtOnXP4gYSTU%3D4Bz4XUs8K9cizbrYGpBg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: JSON serializable error

2018-08-03 Thread Christophe Pettus


> On Aug 3, 2018, at 07:18, Anusha Kommineni  
> wrote:
> TypeError: datetime.datetime(2018, 2, 12, 0, 0, tzinfo=) is not JSON 
> serializable

The error means what it says; there is no default way of serializing a datetime 
into JSON.  You can use the DjangoJSONEncoder, which does allow serializing 
datetimes:


https://docs.djangoproject.com/en/2.0/topics/serialization/#djangojsonencoder

--
-- Christophe Pettus
   x...@thebuild.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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/DCF58620-3F8A-4121-A0FD-7CB3C1922531%40thebuild.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django keeps object references in case of exception

2018-08-03 Thread Christophe Pettus


> On Aug 3, 2018, at 07:23, claudio.cill...@gmail.com wrote:
> 
> It seems to me this is a bug, but I'd like your opinions before actually 
> filing a bug report.

I suspect what you are seeing there is a difference in garbage collection 
behavior.  __del__ is not run immediately upon the reference count reaching 0; 
it's run when the object is garbage-collected, which can be some time later.

--
-- Christophe Pettus
   x...@thebuild.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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/DBEC950B-5D7E-4FD2-9055-23971FAF7193%40thebuild.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django keeps object references in case of exception

2018-08-03 Thread claudio . cilloni
Sorry but... no. It's not mandatory for any Python implementation, but the 
CPython interpreter collects any objects as soon as its reference count 
reaches zero, thus running the __del__ method.

https://docs.python.org/3/c-api/intro.html#reference-counts
https://docs.python.org/3/reference/datamodel.html#object.__del__


On Friday, August 3, 2018 at 7:34:20 PM UTC+2, Christophe Pettus wrote:
>
>
> > On Aug 3, 2018, at 07:23, claudio...@gmail.com  wrote: 
> > 
> > It seems to me this is a bug, but I'd like your opinions before actually 
> filing a bug report. 
>
> I suspect what you are seeing there is a difference in garbage collection 
> behavior.  __del__ is not run immediately upon the reference count reaching 
> 0; it's run when the object is garbage-collected, which can be some time 
> later. 
>
> -- 
> -- Christophe Pettus 
>x...@thebuild.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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bb88a8dc-571a-478a-bd26-2606bf660c1c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django dynamic Database

2018-08-03 Thread carlos
What ? Need more information when you say dynamic database

El vie., 3 de ago. de 2018 5:36 a. m., Cheran Rj 
escribió:

> Hi! how to create dynamic database for each user or organisation
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/3188932a-9f8d-4716-9496-6a11bc87d6cd%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAM-7rO3ZHc-stDBQJii939U%2BaxEQSg539x6o4eqNU_mCDcTY_w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


How to test TestContextDecorator

2018-08-03 Thread Kamil Pluciński
Hi all ;)
I work with this ticket: 29024 . 
I changed decorate_class function in TextContextDecorator 
:

def setUp(inner_self):
context = self.enable()
if self.attr_name:
setattr(inner_self, self.attr_name, context)
try:
decorated_setUp(inner_self)
except:
self.disable()
raise Exception


I have to test it, so I tried something like this:

class TestContextDecoratorImplementation(TestContextDecorator):
some_var = False

def enable(self):
self.__class__.some_var = True

def disable(self):
self.__class__.some_var = False

class TestContextDecoratorTests(SimpleTestCase):

def test_disable_method_after_exception(self):

@TestContextDecoratorImplementation()
class TestWithException(unittest.TestCase):
def setUp(self):
raise Exception("HIDE THIS")

def test_var_is_true(self):
self.assertTrue(TestContextDecoratorImplementation.some_var)


class SimpleTest(unittest.TestCase):
def test_var_is_false(self):
self.assertFalse(TestContextDecoratorImplementation.some_var)

runTest = lambda test: unittest.TextTestRunner().run(test)

result = runTest(TestWithException('test_var_is_true'))
self.assertEqual(result.testsRun, 1)
self.assertEqual(len(result.errors), 1)

result = runTest(SimpleTest('test_var_is_false'))
self.assertEqual(result.testsRun, 1)
self.assertEqual(len(result.failures), 0)


but I can`t remove exceptions from logs:
System check identified no issues (0 silenced).
E
==
ERROR: test_var_is_true 
(test_utils.tests.TestContextDecoratorTests.test_disable_method_after_exception..TestWithException)
--
Traceback (most recent call last):
  File "/home/pluto/git/django/django/django/test/utils.py", line 351, in 
setUp
decorated_setUp(inner_self)
  File "/home/pluto/git/django/django/tests/test_utils/tests.py", line 
1244, in setUp
raise Exception("HIDE THIS")
Exception: HIDE THIS

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pluto/git/django/django/django/test/utils.py", line 354, in 
setUp
raise Exception
Exception

--
Ran 1 test in 0.000s

FAILED (errors=1)
.
--
Ran 1 test in 0.000s

OK
.
--
Ran 1 test in 0.001s

OK


How can I hide it? Or what is good way to test this class?
Regards :D

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/69e80b65-c604-45cf-b48b-e46200d56780%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to make a Purchase Order app?

2018-08-03 Thread Alexander Joseph
Thanks Andréas, very helpful!
One more question - 
Since I'm using class based views and this view requires 2 models I'm 
unsure how to fetch the data from both the models to use in the same view. 
It looks like I need to modify the get_context_data() method but I'm unsure 
how to filter this way. Here is my view now

class PurchaseOrderDetailView(LoginRequiredMixin, TemplateView):
   #context_object_name = "po"
   #model = PurchaseOrder
   template_name = 'financial/purchase_orders/purchase_order_detail.html'

def get_context_data(self, **kwargs):
   context = super(PurchaseOrderDetailView, self).get_context_data(**
kwargs)
   context['purchase_order'] = PurchaseOrder.objects.get()
   context['item'] = PurchaseOrderItem.objects.all()
   return context


So basically what I'm trying to do is filter the 
PurchaseOrder.objects.get() so that the purchase_order.pk = the pk in the 
url, and then filter the PurchaseOrderItem.objects.get() so that the 
item.po_number_fk = purchase_order.pk

Thanks again for all your help!



On Friday, August 3, 2018 at 1:44:15 AM UTC-6, Andréas Kühne wrote:
>
> Hi,
>
> I think you are doing it right. I would remove the PurchaseOrderTotal 
> model however. The reason for this is that the purchase order itself should 
> know it's total and so on. Either you can add a signal on the save of the 
> PurchaseOrderItem - and update the PurchaseOrder total or the PurchaseOrder 
> could calculate the total when required via a method.
>
> I think the easiest way would be to add a method that calculates the total:
>
> @property
> def subtotal(self):
> order_total = 0
> for item in self.purchaseorderitem_set.all():
> order_total += item.qty * item.unit_price
> return order_total
>
> Now it is a property on the purchase order. So calling: 
> purchase_order.subtotal will get the total for the purchase order.
>
> 2 other things:
> 1. You can remove the amount in the PurchaseOrderItem and calculate the 
> total for the row when required (see my example above) - this of course 
> depends on WHEN you want to show the total. The same thing goes for 
> calculating the total on the PurchaseOrder. You could add a property the 
> same way I did for the PurchaseOrder in the PurchaseOrderItem class.
> 2. The names you have given your properties that are foreign keys are not 
> that good from an object oriented perspective. I would for example call the 
> invoice_number field on the PurchaseOrder as "invoice". The same goes for 
> the po_number_fk fields. Because when you assign them or when you want to 
> get a value from the invoice it would be easier to read - 
> purchase_order.invoice.id than purchase_order.invoice_number.id.
>
> Hope that helps somewhat.
>
> If you don't want to calculate the total each time (it all depends on the 
> usage), you can use signals to see when a model is saved/created and then 
> update the subtotal in the PurchaseOrder. See here for information about 
> signals: https://docs.djangoproject.com/en/2.0/topics/signals/
>
> Andréas
>
> 2018-08-02 19:27 GMT+02:00 Alexander Joseph  >:
>
>> I've been working on a Purchase Order app but I'm getting a little 
>> confused how I'm going to put it all together.
>>
>> I have 3 models -
>>
>> class PurchaseOrder(models.Model):
>> po_number = models.IntegerField(default=get_po_number, unique=True)
>> po_date = models.DateField()
>> invoice_number = models.ForeignKey(Invoice, on_delete=models.CASCADE)
>> 
>>
>>
>> class PurchaseOrderItem(models.Model):
>> po_number_fk = models.ForeignKey(PurchaseOrder, 
>> on_delete=models.CASCADE)
>> qty = models.IntegerField()
>> unit = models.CharField(max_length=100, blank=True, null=True)
>> description = models.CharField(max_length=255)
>> unit_price = models.DecimalField(max_digits=6, decimal_places=2)
>> amount = models.DecimalField(max_digits=6, decimal_places=2)
>>
>>
>> class PurchaseOrderTotal(models.Model):
>> po_number_fk = models.ForeignKey(PurchaseOrder, 
>> on_delete=models.CASCADE)
>> subtotal = models.DecimalField(max_digits=6, decimal_places=2)
>> tax = models.DecimalField(max_digits=6, decimal_places=2, 
>> default="7.82")
>> shipping = models.DecimalField(max_digits=6, decimal_places=2)
>> other = models.DecimalField(max_digits=6, decimal_places=2)
>> total = models.DecimalField(max_digits=6, decimal_places=2)
>>
>>
>> the first (PurchaseOrder) holds information about the purchase order 
>> itself. ie. what the invoice number is, the vendor, etc.
>> the second (PurchaseOrderItem) lists items in the purchase order to 
>> purchase
>> the third (PurchaseOrderTotal) totals up the amounts from the items and 
>> adds tax etc. (I may not need this model.. I can probably put this info in 
>> the first model?)
>>
>>
>> Does it look like I'm going about this in the right way or should I take 
>> away the third model and put those fields from the third model into the 
>> first model? Ho

Re: How to test TestContextDecorator

2018-08-03 Thread john-django

Kamil,

Maybe I am missing something, but you can test for exceptions like this:

class TestSomething(unittest.TestCase):

    def test_something_that_raises_an_exception(self):
*with self.assertRaises(Exception):*
# Do something that is supposed to raise an exception

John

On 03/08/18 20:52, Kamil Pluciński wrote:

Hi all ;)
I work with this ticket: 29024 
. I changed 
decorate_class function in TextContextDecorator 
:

def setUp(inner_self):
     context = self.enable()
 if self.attr_name:
 setattr(inner_self, self.attr_name, context)
 try:
         decorated_setUp(inner_self)
 except:
         self.disable()
 raise Exception

I have to test it, so I tried something like this:
class TestContextDecoratorImplementation(TestContextDecorator):
     some_var =False     def enable(self):
 self.__class__.some_var =True     def disable(self):
 self.__class__.some_var =False class 
TestContextDecoratorTests(SimpleTestCase):

 def test_disable_method_after_exception(self):

 @TestContextDecoratorImplementation()
 class TestWithException(unittest.TestCase):
 def setUp(self):
 raise Exception("HIDE THIS")

 def test_var_is_true(self):
 self.assertTrue(TestContextDecoratorImplementation.some_var)


 class SimpleTest(unittest.TestCase):
 def test_var_is_false(self):
 self.assertFalse(TestContextDecoratorImplementation.some_var)

         runTest =lambda test: unittest.TextTestRunner().run(test)

         result = runTest(TestWithException('test_var_is_true'))
 self.assertEqual(result.testsRun, 1)
 self.assertEqual(len(result.errors), 1)

         result = runTest(SimpleTest('test_var_is_false'))
 self.assertEqual(result.testsRun, 1)
 self.assertEqual(len(result.failures), 0)

but I can`t remove exceptions from logs:
|
System check identified no issues (0 silenced).
E
==
ERROR: test_var_is_true 
(test_utils.tests.TestContextDecoratorTests.test_disable_method_after_exception..TestWithException)

--
Traceback (most recent call last):
  File "/home/pluto/git/django/django/django/test/utils.py", line 351, 
in setUp

decorated_setUp(inner_self)
  File "/home/pluto/git/django/django/tests/test_utils/tests.py", line 
1244, in setUp

raise Exception("HIDE THIS")
Exception: HIDE THIS

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pluto/git/django/django/django/test/utils.py", line 354, 
in setUp

raise Exception
Exception

--
Ran 1 test in 0.000s

FAILED (errors=1)
.
--
Ran 1 test in 0.000s

OK
.
--
Ran 1 test in 0.001s

OK

|

How can I hide it? Or what is good way to test this class?
Regards :D
--
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 post to this group, send email to django-users@googlegroups.com 
.

Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/69e80b65-c604-45cf-b48b-e46200d56780%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7cd7e0fd-9d78-ba59-d17a-5ed5ab5ed31b%40martinhome.org.uk.
For more options, visit https://groups.google.com/d/optout.


Re: Django dynamic Database

2018-08-03 Thread Mikhailo Keda

Do you mean multi-tenancy?
If so - check those apps - https://djangopackages.org/grids/g/multi-tenancy/

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/558f7ed0-4dc4-4bac-b2e4-c04612ff6ed3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: GEOSGeometry function dies with error pure virtual method called message

2018-08-03 Thread Mikhailo Keda
I replicated this,
No traceback, python crashes with a message:
libc++abi.dylib: Pure virtual function called!

I'm assuming this is related to GDAL on macOS.
Without debug it works fine.

Environment details:

> Django 2.0.7
Python 3.7.0
GDAL 1.11.5
macOS High Sierra

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1a450938-c0e8-4ce9-af10-6ad7b99b8ad0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.