Model.objects.create as default

2021-02-06 Thread degnon...@gmail.com
hi, say I have this model

class Event(models.Model):
  ...
  metrics = models.OneToOneField("evmetrics.Metrics", 
on_delete=models.PROTECT,
default=Metrics.objects.create)

I want to be sure of what I'm writing here, for each new Event object 
created, a new Metrics object will be create and link to the event by a 
OneToOne relationship, is there any chance this is really bad code or this 
could be a 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/541e8075-0ded-41cd-a565-e552c66a0183n%40googlegroups.com.


IntegrityError on a foreign key constraint

2021-01-30 Thread degnon...@gmail.com
Hi, I'm having a really incomprehensible error currently. We are working 
with three models here, "DataImport", "Contact" and "Dataset", the 
DataImport model import data from a file to a Dataset object, the data is 
imported as a Contact object , the DataImport model have a foreign key to 
the Dataset model. This is how the app works:

- a user upload a file
- we convert the content of the file to a TablibDataset or TablibDatabook, 
these are tablib (python package) classes, don't worry too much about this, 
tablib have their own Dataset and I have my own, that's why I import the 
tablib classes with aliases
- if the loaded data is a TablibDataset, the import start and create 
contacts from the loaded data (this works)
- if the loaded_data is a TablibDatabook, the databook is split into 
multiple sheet (yes I'm working with excel files) and new Dataset (my 
model)  and DataImport objects are created to handle the import for each  
sheet (here is the issue)

All import are done as async task using the django_q package
The issue I have is that, when I create a new dataset, start the import and 
try to add a new contact I get this:
```
insert or update on table "datasets_contact" violates foreign key 
constraint "datasets_contact_dataset_id_9dda7f76_fk_datasets_dataset_id"
DETAIL:  Key (dataset_id)=(39) is not present in table "datasets_dataset".
```
It seems like the dataset is not save in db that's why I'm getting this 
error when I try to create a new contact, but I'm creating my Dataset 
object with Dataset.objects.create(), I don't understand the problem.

The code for all this is a bit long, so here is a gist with all the 
necessary code 
https://gist.github.com/Tobi-De/411ee7b7fc988864869c8d7ad93ab34f

The method that create the Dataset and DataImpot objects is the class 
method "create_import_from_databook"

-- 
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/dbfc0761-347d-47a5-9689-9886ce1e37fcn%40googlegroups.com.


Auto refreshing frontend

2021-01-05 Thread degnon...@gmail.com
Hello, 

I am building a very simple website in which the main page allows users to 
import their contacts via csv or excel files to a postgres database.

I have a page that displays whether or not the import of contacts is 
finished, I need my frontend to update automatically as soon as the task is 
finished in the background, basically when the data is fully imported into 
the database.
I'm thinking of looking for a way to refresh the page every 5 second or 
something like that, but I don't think this is a good idea.
I am not quite sure how to approach this. I still have some learning to do, 
but I need some guidance on what approach to take. I am thinking I will 
need to use JQuery/Ajax? So write my HTML template and then link it to a 
Javascript script that does the refresh?

I think I can figure out how to refresh the page, but how do I have the 
model queried, view called, and new data fed to the HTML template each time 
the page auto-refreshes?

I am also not sure if web sockets are what I need. If ajax is not the 
answer here, an example of scenario where ajax is useful would be really 
helpful, I always hear about it but I don't know when it can be useful.

Any help or link to resources is immensely appreciated!!

Thank you.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5560f982-adc8-4498-9dbf-ddd7677d6a51n%40googlegroups.com.


Deploy you django project

2020-10-11 Thread degnon...@gmail.com

HI guys I hope you are all doing well, for those of you looking for a way 
to deploy your django projects i wrote a blog post on how to achieve that 
on a personal blog i started recently (today in fact).Feel free to take a 
look and give me your feedback. You can check the article here:  
https://www.tobidegnon.com/blog/post-detail/host-your-django-project-on-digital-ocean-with-dok/

-- 
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/37c9e9e0-4d6a-4366-94d7-1de18d214949n%40googlegroups.com.


Mass Emailing

2020-10-01 Thread degnon...@gmail.com

Hi, hope every one is doing fine, I have an issue that I have not been able 
to resolve for several months now. I have two apps where  I need to send a 
bunch of emails on a monthly basis, The first app is host on heroku and the 
second on DigitalOcean with dokku, for async task I'm using Django_Q and 
Redis is used as broker, when I need to send 1 or 2 emails, or even 
something like 100, there is no issue, the emails are sent and the task is 
marked as successful in the Django_q admin section, but when I need to send 
just 200 or 500 (send 500 is supposed to be nothing), the task is never 
accomplished, I don't receive any error message sand even if I wait for 
days the task is never marked completed and all emails are not sent, at 
first I think it was a resources issue, in the case of my first app I'm 
using the heroku hobby-dev plan, maybe this is two low for the work I need 
to get done, but for my second app I'm using the 15$ plan on DigitalOcean, 
for just 500 emails i think that's enough, Maybe I should use celery 
instead of Django_q, I don't know, I need to know what are the minimum 
requirements to send a lot(and by a lot I mean something like 50k for 
example) emails with a Django app, and how to do this efficiently. An 
article, a package name, anything would be helpful. I'm using amazon SES 
for both apps. 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/5d981f11-c996-47bc-8897-72a43b4a76a7n%40googlegroups.com.