These are chat archives for django/django

8th
Oct 2017
Anish Shrestha
@annshress
Oct 08 2017 08:41
class MyFilter(django_filters.FilterSet):
  def __init__(self, data=None, queryset=None, prefix=None, strict=None):
    # based on the data from request.query_params construct other filters and
    # add to base_filters as well.
    filter = df.CharFilter(name="extra__{}".format(each), lookup_expr='exact')
    self.base_filters[each] = filter
    ...

Now when I call filter_class from the API view, the base_filters are preserved. After every requests, the extra-filters I add are preserved.
I expected at every request, a new instance will be created with new extra-filters.

But extra-filters keep on getting appended on every new request, despite the fact I am calling it MyFilter(data=self.request.query_params). And furthermore, on every unique request, I check id of the initialized filter_class and find that they are same.

like,
id(my_filter_instance)

What am I doing wrong?

cs89gr
@cs89gr
Oct 08 2017 10:46

hello

i need some help
I have a website where the user can be put three numbers on my html template and get some results from my personal mathematical algorithm. the result save at user personal table on my database and can see in specific tab in my website.

my problem is where the algorithm to calculate result maybe take time between 5-10 minutes in this time the browser stay on reload. if user change tab or close browser or maybe have problem with internet connection then loose that request and need again to put the numbers and again wait for results.

I want after the user request from my form in html to keep this request and work my algorithm without reload the page and where the algorithm finish then to send the user some email or message or just need the user visit the tab of results to see new results.

that I want to avoid the problems where the algorithm is in running and user loose data or request or time.

is easy to do that using suproccess,celery or RabbitMQ ?

any idea ?

here the code

views.py

def math_alg(request):
    if request.method == "POST":
        test = request.POST.get('no1')
        test = request.POST.get('no3')
        test = request.POST.get('no3')
        #start algorith
        calc_math(no1,no1,no3,result)
        instance = rmodel.objects.create(user=request.user,rfield=result)
        instance.save
    return render(request, 'page.html', {'result': result})

html :

<form action="" method="POST">{% csrf_token %}
  op math calculate:<br>
  <input type="number" name="no1" step="any" min="0" max="1" value="0.5">
  <input type="number" name="no2" step="any" min="0" max="1" value="9999">
  <input type="number" name="no3" step="any" min="0" max="1" value="1000000000000000">
<br>
  <input class="btn btn-primary" type="submit">
{{result }}
</form>
Joseph Safwat Khella
@JosephSKh
Oct 08 2017 14:10

hello guys ! ,, evenings
I have a question
if I have a model like
{
user1:
user2:
}
and I want to get all rows with distinct on user1 & user2
ex:
row1: user1 = 1 , user2 = 2
row2: user1 = 3, user2 = 1

row3: user1 = 2, user2 = 1

this shall return only 2 rows
the first and second
what shall my query look like?
thx