Move __reinit__ to base class.
This commit is contained in:
		
							parent
							
								
									de93f81331
								
							
						
					
					
						commit
						4d98176c80
					
				
					 1 changed files with 10 additions and 7 deletions
				
			
		|  | @ -41,6 +41,16 @@ class ObjectBase: | ||||||
|         self.photodb = photodb |         self.photodb = photodb | ||||||
|         self.deleted = False |         self.deleted = False | ||||||
| 
 | 
 | ||||||
|  |     def __reinit__(self): | ||||||
|  |         ''' | ||||||
|  |         Reload the row from the database and do __init__ with it. | ||||||
|  |         ''' | ||||||
|  |         row = self.photodb.sql_select_one(f'SELECT * FROM {self.table} WHERE id == ?', [self.id]) | ||||||
|  |         if row is None: | ||||||
|  |             self.deleted = True | ||||||
|  |         else: | ||||||
|  |             self.__init__(self.photodb, row) | ||||||
|  | 
 | ||||||
|     def __eq__(self, other): |     def __eq__(self, other): | ||||||
|         return ( |         return ( | ||||||
|             isinstance(other, type(self)) and |             isinstance(other, type(self)) and | ||||||
|  | @ -770,13 +780,6 @@ class Photo(ObjectBase): | ||||||
|         else: |         else: | ||||||
|             self.simple_mimetype = self.mimetype.split('/')[0] |             self.simple_mimetype = self.mimetype.split('/')[0] | ||||||
| 
 | 
 | ||||||
|     def __reinit__(self): |  | ||||||
|         ''' |  | ||||||
|         Reload the row from the database and do __init__ with them. |  | ||||||
|         ''' |  | ||||||
|         row = self.photodb.sql_select_one('SELECT * FROM photos WHERE id == ?', [self.id]) |  | ||||||
|         self.__init__(self.photodb, row) |  | ||||||
| 
 |  | ||||||
|     def __repr__(self): |     def __repr__(self): | ||||||
|         return f'Photo:{self.id}' |         return f'Photo:{self.id}' | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue