Sunday August 27th from 10:00pm to 01:00am Monday Morning PST

247Apps and MyNetworkSolution VPS Scheduled Maintenance

 

We will be conducting an upgrade to our VPS Servers to provide greater security, stability and speed for our clients across United States and Canada. As usual, this upgrade will occur during the wee hours of the morning when you are all asleep.
Starting Sunday August 27th @ 10:00pm PST. Our scheduled window for this maintenance cycle should be under 3 hours.
We apologize for any inconvenience this disruption may cause and thank you for your patience.

Thank you,
247AppsMobi – Web Services of MyNetworkSolution Dev Team

Sunday February 12th from 11:00pm to 02:00am Monday Morning PST

247Apps VPS Scheduled Maintenance

 

We will be conducting an upgrade to our VPS Servers to provide greater stability and speed. This upgrade will occur during the wee hours of the morning when you are all asleep.
Starting Sunday February 12 @ 11:00pm PST. Our scheduled window for this maintenance cycle should be under 3 hours.
We apologize for any inconvenience this disruption may cause and thank you for your patience.

Thank you,
247AppsMobi – Web Services of MyNetworkSolution Dev Team

How to Return JSON Encoded Response for a non-dict object

In DJango, an HttpResponse sub-class helps to create a JSON-encoded response. It was called Serialized-Object response in Django < 1.7. Its default Content-Type header is set to application/JSON. The first parameter (data set), should be a dict instance. If non-dict object is passed in as the first parameter, a TypeError will be raised. To fix this error, we just need to add a parameter called “safe” to False in the method call JsonResponse.

TypeError: In order to allow non-dict objects to be serialized set the safe parameter to False

This is the fix:

return JsonResponse(["a", "b", 1, 2], safe=False)

The safe boolean parameter defaults is True. If it’s set to False, any object can be passed for serialization (otherwise only dict instances are allowed).

Example non-dict object:

some_object = [{‘pk’: 86, “model”: “machine_models.machinemodel”, “notes”: “This is warehouse imported machine.”}]

return JsonResponse(some_object,safe=False)

 

A complete sample:

from django.http import JsonResponse

def home_details(req):
    response = {
        'id': 1,
        'address': '123 Main St., San Jose, CA 95111',
        'beds': 3,
        'baths': 2,
        'status': Sold
    }
    return JsonResponse(response)

Django errors while working with components

1) OperationalError at /admin/csv_app/invoicefile/add/
no such table: csv_app_invoicefile
==>solve this error by cmd
makemigrations csv_app
migrate

2)System check identified no issues (0 silenced).
You have 6 unapplied migration(s). Your project may not work properly until you
apply the migrations for app(s): csv_app.
Run ‘python manage.py migrate’ to apply them.
July 13, 2021 – 14:55:01
Django version 3.2.5, using settings ‘proj3.settings’
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

==>to fix this error, go to cmd enter:
$python manage.py makemigrations csv_app
$python manage.py migrate
$py manage.py runserver

3)os.path.join(BASE_DIR, ‘static’),
NameError: name ‘os’ is not defined
==>add this line in settings.py
import os

Inner class Meta

In Django this class works like post_meta in WordPress. In Django, it acts as a configuration class and keeps the configuration data in one place. Class Meta is the place in your code logic where your model.fields MEET With your form.widgets. So under Class Meta() you create the link between your model’ fields and the different widgets you want to have in your form.
Model metadata is “anything that’s not a field”, such as ordering options (ordering), database table name (db_table), or human-readable singular and plural names (verbose_name and verbose_name_plural). None are required, and adding class Meta to a model is completely optional.
A complete list of all possible Meta options are in this document (https://docs.djangoproject.com/en/dev/ref/models/options/):
To override the database table name, use the db_table parameter in class Meta.
db_table
db_table = ‘”name_left_in_lowercase”‘
app_label
app_label = ‘myapp’
base_manager_name
db_tablespace
default_manager_name
default_related_name
get_latest_by
managed
order_with_respect_to
ordering
permissions (Defaults to (‘add’, ‘change’, ‘delete’, ‘view’)
proxy
required_db_features
required_db_vendor
indexes
unique_together
index_together
constraints
verbose_name
verbose_name_plural
label
label_lower