This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# good bad dict | |
context={"first_name": user.first_name.capitalize(),"company": g.user.get_company_name,"last_name": g.user.last_name.capitalize(),"username": user.username,"password": password} | |
# difficult to debug and difficult to find a bug | |
# good dict | |
context = { | |
"first_name": user.first_name.capitalize(), | |
"company": g.user.get_company_name, | |
"last_name": g.user.last_name.capitalize(), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# bad import | |
from sqlalchemy import Boolean, Column, create_engine, DateTime, ForeignKey, Integer, MetaData, String, Table, Text | |
# good import | |
from sqlalchemy import ( | |
Boolean, | |
Column, | |
create_engine, | |
DateTime, | |
ForeignKey, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# wrong one! | |
wrong_dict = {1: 'Geeks', 2: 'For', 3:{'A' : 'Welcome', 'B' : 'To', 'C' : 'Geeks'}} | |
# right one! | |
right_dict = { | |
1: 'hi', | |
2: 'there', | |
3: { | |
'A': 'how', | |
'B': 'are', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Topping(models.Model): | |
name = models.CharField(max_length=30) | |
class Pizza(models.Model): | |
name = models.CharField(max_length=30) | |
toppings = models.ManyToManyField(Topping) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Waiter(models.Model): | |
restaurant = models.ForeignKey(Restaurant, on_delete=models.CASCADE) | |
name = models.CharField(max_length=50) | |
def __str__(self): | |
return "%s the waiter at %s" % (self.name, self.restaurant) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Place(models.Model): | |
name = models.CharField(max_length=50) | |
class Restaurant(models.Model): | |
place = models.OneToOneField(Place,on_delete=models.CASCADE) | |
serves_hot_dogs = models.BooleanField(default=False) | |
NewerOlder